Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i update a jenkins job using the api

Tags:

I have to create/update a jenkins job using its api because all of my jobs are using parameters which are also used by other scripts and I am trying to centralize the scripts so when i change it in one place, the change reflects in all.

currently, if someone changes the script, they they also have to manually edit the parameters of the jenkins job as well.

I saw the example of the Remote API for creating jobs and was able to successfully create test jobs but how can i edit an existing job besides deleting it and creating it again(which isnt an option as i have to maintain the build history).

like image 984
dsymquen Avatar asked Mar 19 '14 06:03

dsymquen


1 Answers

You could use python like this:

from jenkinsapi.jenkins import Jenkins jenkinsSource = 'http://10.52.123.124:8080/' server = Jenkins(jenkinsSource, username = 'XXXXX', password = 'YYYYY') myJob=server.get_job("__test") myConfig=myJob.get_config() print myConfig new = myConfig.replace('<string>clean</string>', '<string>string bean</string>') myJob.update_config(new) 
like image 134
Dave Avatar answered Oct 08 '22 07:10

Dave