1

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

Codor
  • 17,447
  • 9
  • 29
  • 56
Ravisha
  • 3,261
  • 9
  • 39
  • 66
  • possible duplicate of [How to set programmatically recipients of Jenkins Email-ext plugin?](http://stackoverflow.com/questions/18601776/how-to-set-programmatically-recipients-of-jenkins-email-ext-plugin) – Tim Biegeleisen May 18 '15 at 06:29
  • @Tim: My question is to update all the jobs with new set of recipients. I need to get an API to update the recipients. Where as in the link provided , the msg object is already available. also the other question is related to Editable Email notifications , which is a plugin for Jenkins. What i am asking is regarding the default email notification – Ravisha May 18 '15 at 06:38

1 Answers1

1

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:

recipients shows in jenkins job's config.xml

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

mainframer
  • 20,411
  • 12
  • 49
  • 68
  • thanks for your answer. As an alternative i checked this option. But i was wondering if there are any API to do this. What you mentioned could be done without scripts. just open them in text editor and replace all.. i was thinking in terms of scriptlets. – Ravisha May 25 '15 at 07:23
  • I don't see any such specific API that can do this. You are absolutely correct, The method I mentioned can be done by using something like `sed` command. Anyway, if you come up with a scriptlets solution, do be shy to share with us. Thank you. – mainframer May 25 '15 at 09:34
  • I've found an groovy script which I think what you are looking for: https://github.com/jenkinsci/jenkins-scripts/blob/master/scriptler/updateEmailAddress.groovy – mainframer May 26 '15 at 14:54
  • thanks @mainframer. that does solve the question. Just a minor change, we need to save the job after assigning the new email address. you may update your answer with this link – Ravisha May 27 '15 at 15:44