pycontribs / jenkinsapi

A Python API for accessing resources and configuring Hudson & Jenkins continuous-integration servers
http://pypi.python.org/pypi/jenkinsapi
MIT License
858 stars 485 forks source link

Upload node configs with an xml content type #793

Open mrrsm opened 4 years ago

mrrsm commented 4 years ago

Jenkins is throwing an error when the content type is not xml when uploading a node config.

fun4jimmy commented 3 years ago

Is there any chance this could get merged? Without this, all calls to jenkinsapi.Node.set_config_element fail with an internal error, return code 500.

Tested with Jenkins 2.277.4 and jenkinsapi 0.3.11.

Amor122 commented 1 year ago

Actually, when I use the basic api of jenkins( POST /computer/test4/config.xml) to update my node config or job config ,it alerts me to add Host and Content-Length in the request headers .My jenkins verison is 2.361.4,and jenkinsapi is 0.3.13.So I think it may be a long time for users to have truble on updating their config by Jenkinsapi.

I have used Requests to avoid this defect, the program segment is wrote as follows: `python old_config = """<?xml version="1.1" encoding="UTF-8"?>

test5 /data 5 NORMAL 127.0.0.1 10009 0f4ad930-938b-4440-9d0d-14aae7951b61 -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 -Dnative.encoding=UTF-8 60 10 15 true """ new_config = old_config.replace('2', '3') raw_data = new_config.encode('utf-8') content_length = len(raw_data) host = '127.0.0.1' headers = { 'Content-Length': str(content_length), 'Host': host } response = requests.post('http://127.0.0.1:8080/computer/test5/config.xml', auth=auth, data=raw_data, headers=headers) ` I think we can fix this defect by modifying node.py on line 347 with default headers.
mghesh-yseop commented 9 months ago

Can someone look into this ? I tried to run upload_config with the same data received from get_config(), and it fails. But this code calling post_xml_and_confirm_status works like a charm