Jenkins: Send email to recipients of the triggered job

1.1k views Asked by At

I have two Jenkins jobs. One trigger the other using "Parameterized Trigger Plugin".

In case of failure, the second build should send email using "Email-ext plugin".

The email should be send from the second job but to the recipients list of the first. I've tried using the parameters, but failed.

2

There are 2 answers

0
Slav On

The latest version of Email-Ext plugin has Upstream Committers option. Try updating.

0
David On

As part of your build steps, create a property file to send downstream and copy the file to the folder of the next job. Use the Inject environment variables plugin in the second job to import the file.

In Job 1's build steps you could do something like

echo Recipients_Notified=%BUILD_USER_EMAIL%, %Distribution_List% cc:%[email protected]% > email.properties
echo Subject_Line=%APP% Pipeline>> email.properties
echo Line_1=information you want sent from first build to be in the communication>> email.properties
copy email.properties "..\%APP% Job Name\email.properties"

In Job 2 you can add to that file or overwrite it with a different message once the build is successful. Importing the file a second time will overwrite the parameters imported the first time.