How do i programatically set the email recipients for a jenkins job - email

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

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

Related

Cannot attach my Extent report in editable email plugin. My workspace in Jenkins job is empty. is that the reason?

Maven java Selenium Project. I have been building jobs successfully. But I cannot attach My report to send email to outlook.
enter image description here
I am able to add the report to the body of the email, which displays without any CSS. Please help.
enter image description here
In 'Editable Email Notification', ideally, you need to place the file to be attached in "workspace" of the job. & then use filename.extension in 'Attachments'.
https://i.stack.imgur.com/Bl79T.png
If you are using a slave/agent node to build a job, you will find the workspace in root directory of agent node. -> Root_directory/workplace/job_name.
or you may find your job's workspace in "build.xml" of your job.(jenkins/jobs/job_name/builds/build_no/build.xml)
I had faced similar issue with no attachments in automated mail :)
Solution - update the url as per the location where file is generated .
Example - I created a job named - "AutoRunJob" -> Workspace -> File ( generating html )
my path in the editable email notification - target/test-output/LoggerReport/dashboard.html
Note : In Case no emails are flowing check what triggers it is set to by clicking on advance settings inside editable email notification configurations .

Media not found Exception In Email Business Process (Hybris)

I've created a process to be able send email to the user on order confirmation.
The problem is that on the DEV environment everything goes well but when I did a deploy to UAT server
I got an exception during the task execution ( " Media not found (requested media location: hf0/h27/8861015965726.bin) ").
Any Ideas what could be happening ?
How can this issue be resolved and what causes this issue.
hybris creates emails using Velocity templates. Those Velocity Templates are stored as Medias on the hybris Servers. hybris Medias consist of two parts: an entry in the respective table in the database and a file on the hard drive. The database entry stores metadata about that media while the file stores the actual content.
Now what hybris is telling you, is that the file on the hard drive is missing. The database entry directs to a file that is not existing. There could be a lot of reasons why that file is missing:
It was deleted during deployment.
It wasn't created during deployment.
The hybris server has no access/access rights to that directory.
In a clustered environment the file could have been stored on another node and is not accessible on the current node.
Media could be the email itself as Johannes stated, but it can also be a part of the email, an image set from the CMS cockpit for example.
To fix this issue you have to master your impex flows.
First be sure that impex contain all the data needed to create properly the email.
Then know what is imported when you deploy and update your system.
Be sure that mandatory files are imported during initialization.
Be sure that data that can be managed by webmasters are not reset by impex during update.
If a data is created during the update because init is already done then be sure that is won't be played after each update.
As the media file is not found, you can
1. go to hmc-->Multimedia-->Media, in search panel,
2. click "search additional attributes" dropdown box, select "PK of file"
3. use "8861015965726" as PK of file to search
Then you can find out what file is missing and you can import impex or upload using hmc to fix this problem.

Dreamfactory - Why is my server event script not called?

I have a bitnami instance that I use to run DF 2.12.0, on which I added a custom “Remote service” (a HTTP REST API). I would like to use server-side event scripting functionalities to pre-process request data before sending it. I have this pre-processing Node js test script, that is linked to the “pre_process” event of my resource :
console.log("test");
But it seems that this script is not executed, after having a look at the DF log file :
However, all DF built-in functionalities such as the user management service seem to work with event scripting. Here is the same log file about a script linked to the user.session.get.pre_process event, that is indeed called :
Strangely, the complete path of my main event script is netwrixapi.search.post.pre_process, but the first log file image only mentions a call to the event “netwrixapi.post.pre_process” (without my resource “search”).
I included the “X-DreamFactory-Api-Key” in my request header, which references an app with a full-access role to API and script sources for all HTTP methods :
I also set APP_DEBUG=true and APP_LOG_LEVEL=debug in my .env file, without any luck.
Any ideas ?
Problem finally solved : seems like the log_events variable wasn't set to true by default (even if the official documentation says so) in my {$HOME}/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/config/df.php file.

Jenkins email plugin doesn't send email to user who broke the build

I've setup Jenkins to send emails only to users who broke the build using email-ext plugin, but I'm getting this error:
Not sending mail to unregistered user user#example.com because your SCM claimed this was associated with a user ID ‘John Smith' which your security realm does not recognize; you may need changes in your SCM plugin
I don't really understand what this error means, is the problem in our SCM, or in the email plugin? The emails are taken from the commit history, should I register them somewhere so Jenkins will start working?
For reference, this is the code around the error message in the plugin's source code:
} catch (UsernameNotFoundException x) {
if (SEND_TO_UNKNOWN_USERS) {
listener.getLogger().printf("Warning: %s is not a recognized user, but sending mail anyway%n", userAddress);
} else {
listener.getLogger().printf("Not sending mail to unregistered user %s because your SCM"
........
How do I enable SEND_TO_UNKNOWN_USERS?
The error message is also mentioned in this bug report.
For version V2.61 or above this can be configured via a radio button.
Go to
Manage Jenkins -> Configure System -> Extended E-mail Notification
and tick the radio button for Allow sending to unregistered users
Edit: If this does not work, see https://stackoverflow.com/a/45353810/492336 for another solution.
OK, after some experiments this is what I found out:
Jenkins takes the email part of the committer (not the author). For example for a commit message that looks like that:
Author: John Smith <author1#example1.com> 2017-07-27 17:15:39
Committer: John Doe <committer1#example2.com> 2017-07-27 17:15:39
Parent: 9c3ff18dda8ca6f7b7ac4ebab4c76d3c85891a33 (commit)
Branch: master
Jenkins will take "committer1", and create a brand new user under People with User ID "committer1" and email "". Unless that user has a password however, it will be considered unregistered so you need to go to Configure for that user and add a password field to it:
So this is one way to fix the error, but you have to do it for every user and in a big team it can be tedious.
Put the line bellow in your jenkins startup script
-Dhudson.tasks.MailSender.SEND_TO_UNKNOWN_USERS=true
The newest Jenkins security directive only allow sending mail to registered user. The line above bypass this configuration.
Given jenkins takes the first part of the email address and creates a user, I made my team have their jenkins user name be the first part of their email address. This removed any overhead of having to maintain two separate users.

In coming emails not updating issue fields in Redmine

I am trying to set up Redmine so that it can receive emails to create tickets .
The command I use to fetch emails is
rake --trace redmine:email:receive_pop3 RAILS_ENV="production" host=my.mail.server port=110 username=born#mydomain.com password=***** project=foobar
email contents are like
Project: foobar
Tracker: Bugz
Status: New
Priority: Normal
On receiving this email redmine created a new ticket . However files Tracker,Status and Priority is not getting updated with the values from email . Instead the entire email body is getting updated in Description field of the new ticket.
Are my emails not in the correct format ?
Redmine only allows setting attributes from the mail body which are explicitly enumerated on the command line.
You can specify which attributes are allowed to be set using the #allow_override# argument to the rake task similar to this:
rake redmine:email:receive_pop3 RAILS_ENV="production" ... allow_override=project,tracker,status,priority
Please see the documentation at http://www.redmine.org/projects/redmine/wiki/RedmineReceivingEmails#Issue-attributes for details.