I would like to know how can I sent an email from a downstream build to the upstream recipient list? There is an option to sent the email to the upstream git committers but its not what i want to achieve.
1 Answers
Hm... depending on what you want to do this might be rather complicated.. or super easy...
The super easy scenario...
Are you just wanting to send it to the same static list?
Then you can just type in the identical recipient list in both the upstream and downstream job to get it to send to identical lists. :)
The complicated scenario
Are wanting to pass down a dynamic recipient list? If so, that's going to be more complicated..
But all is not lost! How about triggering the downstream build via the post ext-email script and passing down the recipient list as a build parameter. That way, all you have to do is just use that as the recipient list in the downstream job.
Here is a breakdown of the steps you need to do for this method:
In the downstream job
- Add a string build parameter called "UpstreamRecipientList"
- Add a dummy email in the recipient list if there isn't one there already. This is to prevent Jenkins from skipping the email step since there won't be any email addresses to begin with (e.g. we are setting it dynamically later). Otherwise, the ext email won't even bother executing our pre/post scripts since there aren't any emails to send it to.
Open the "Advanced Settings" of the ext-email plugin and paste this in the "Pre-send Script". It will update the recipient list with the value stored in the "UpstreamRecipientList" parameter.
msg.setRecipients(javax.mail.Message.RecipientType.TO, build.buildVariableResolver.resolve("UpstreamRecipientList"))
In the upstream job
- Again, add a dummy email in the recipient list if you don't send emails in the upstream job. If you do, you do not need to perform this as the post email script will get triggered.
Open the "Advanced Settings" of the ext-email plugin and paste this in the "Post-send Script". It will trigger a new build passing in the current recipient list. Note that you will need to replace the "myDownstreamJob" string with whatever your downstream job is called!
jenkins.model.Jenkins.instance.getItem("myDownstreamJob").scheduleBuild(5, new hudson.model.Cause.UpstreamCause(build), new hudson.model.ParametersAction([ new hudson.model.StringParameterValue( "UpstreamRecipientList", msg.getRecipients(javax.mail.Message.RecipientType.TO).join(",") ) ]));
- Click "Add Trigger" and add an "Always" trigger. This is so that every build will execute the post email script and trigger a downstream job.

- 2,431
- 17
- 15