Reputation: 3343
I am trying to update the email recipients for loads of jenkins job with new set of email lists, I am unable to find the right API to do so. Although this could be updated in the config file directly but wanted to use Jenkins APIs if available any
Edit : I am referring to the below field Post-build Actions: E-mail Notification > Recipients
Upvotes: 1
Views: 2545
Reputation: 22069
Well. Currently I do not have the code but I have the thoughts.
1st step:
You can use whatever jenkins API (REST, python wrapper,etc...) to dump all your job names into a txt file, saying job_list.txt
.
Below is an example. And you can find the useage from This link.
import jenkins
j = jenkins.Jenkins('http://your_url_here', 'username', 'password')
j.get_jobs()
2nd step:
As you can see, each job has an config file with path like $JENKINS_HOME/jobs/job_name/config.xml
. This can also be accessed from your browser. From browser it looks like this:
So your question can be simplified into either:
"How to update the recipients value of config.xml from each job folder under $JENKINS_HOME/jobs
directory".
Or:
"How to update the recipients value of config.xml from each job url like http://your_jenkins_url/job/each_job_name/config.xml
".
So this can be done by any script language like python
,ruby
,shell
,vb
or whatever http-like lib like 'urllib2', 'requests' etc...
3rd step:
After all the config.xml file updated, don't forget to restart your jenkins to take effects.
Good luck, buddy!
Edited(2015-05-27)
There is an existing Groovy script written by @edalquist which can update the email address in a programatically way. https://github.com/jenkinsci/jenkins-scripts/blob/master/scriptler/updateEmailAddress.groovy
Upvotes: 1