Jacob
Jacob

Reputation: 51

How to POST an updated config.xml using Jenkins REST API?

I wanna write a groovy script to bulk update my job configuration using Jenkins REST API. But I am quite confused by its API doc (http://localhost:8080/jenkins/job/my_job_name/api/).

Fetch/Update config.xml

To programmatically obtain config.xml, hit this URL. You can also POST an updated config.xml to the same URL[http://localhost:8080/jenkins/job/my_job_name/config.xml] to programmatically update the configuration of a job.

How am I gonna POST an xml file to an url mentioned above?

Upvotes: 2

Views: 8289

Answers (3)

jin
jin

Reputation: 19

curl -X POST -H 'Content-Type: application/octet-stream' http://<ip>/job/<job name>/config.xml --user uname:upass --data-binary @./test.xml

Many answers set Content-Type: application/xml, and it didn't work in my Jenkins. I try to set Content-Type: application/octet-stream and it work successfully.

Upvotes: 1

Edward Shen
Edward Shen

Reputation: 51

The below curl command works for me.

curl --user $USER:$API_TOKEN -X POST http://localhost:8080/job/test/config.xml -H 'Content-Type: application/xml' --data-binary "@mymodifiedlocalconfig.xml"

Upvotes: 5

Jacob
Jacob

Reputation: 51

I tried cURL and it worked.

curl -F "file=@updated_config.xml" "http://localhost:8080/jenkins/job/my_job_name/config.xml"  

Note: U will need to toggle off "Prevent Cross Site Request Forgery exploits" in Jenkins config.

Upvotes: 0

Related Questions