jenkinsapi icon indicating copy to clipboard operation
jenkinsapi copied to clipboard

Upload node configs with an xml content type

Open mrrsm opened this issue 4 years ago • 3 comments

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

mrrsm avatar Sep 22 '20 21:09 mrrsm

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.

fun4jimmy avatar May 18 '21 15:05 fun4jimmy

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 = """ test5 <remoteFS>/data</remoteFS> <numExecutors>5</numExecutors> NORMAL <retentionStrategy class="hudson.slaves.RetentionStrategy$Always"/> 127.0.0.1 10009 <credentialsId>0f4ad930-938b-4440-9d0d-14aae7951b61</credentialsId> <jvmOptions>-Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 -Dnative.encoding=UTF-8</jvmOptions> <launchTimeoutSeconds>60</launchTimeoutSeconds> <maxNumRetries>10</maxNumRetries> <retryWaitTime>15</retryWaitTime> <sshHostKeyVerificationStrategy class="hudson.plugins.sshslaves.verifiers.NonVerifyingKeyVerificationStrategy"/> <tcpNoDelay>true</tcpNoDelay>

""" 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.

Amor122 avatar Jun 18 '23 08:06 Amor122

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

mghesh-yseop avatar Feb 06 '24 15:02 mghesh-yseop