Manoj chhablani
Manoj chhablani

Reputation: 51

how to get build failure reason in email content of Jenkins jobs

I have configured Jenkins job for gradle build making and also configured email ext plugin.Now i want when build fails, the build failure reason should be mentioned in email content along with build log attachment. Kindly let me know how to do this.

Upvotes: 3

Views: 1089

Answers (1)

Ivan
Ivan

Reputation: 2320

Email ext can accept e-mail body content from a variable. In combination with EnvInject one can make a very detailed e-mail with a good structure.

You can achieve this by doing the following:

At each step that you want to record ( for example at some possible warning message in a build, or after each important step ) - write something to the file in build workspace. You can start at the beginning of a build with example:

rm -f email_preparation.txt # remove the preious run e-mail file;
echo "Hi,<br><br> This is an automatic e-mail from Jenkins regarding foo.<br>" > email_preparation.txt

Then append something:

echo "There were some warning during compilation of project 'bar'" >> email_preparation.txt

After the build run read the file to a variable and inject it with EnvInject:

echo "MAIL="`cat ${WORKSPACE}/email_preparation.txt` > ${WORKSPACE}/env.txt

Finally, simply add ${MAIL} to e-mail body. Don't forget to make use of html formatting.

Upvotes: 1

Related Questions