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).
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With