Jenkins comes with a good support for analyzing JUnit tests results and producing reports, for instance, a trend graph — number of tests executed over builds:
It would be nice to include the test trend graph into email notifications.
The email-ext plugin allows you to easily attach files, but we need more. The thing is the image is rendered when you access the URL like
http://jenkins.local:8080/job/myjob/test/trend. So we need to upload an image from the URL. I’d need to write a Groovy script for that.
There is an easier way: download the image to a file and attach it:
Oops, “Authentication required”. In my setup,
anonymous doesn’t have access to the jobs. So I created a user
job and had to give her
Here is a little script to download the file with authorization:
1 2 3 4 5 6
Briefly, this shell build step gets a URL to the job itself w/o the current build number (
http://jenkins.local:8080/job/csdk/), then logs in as the
job user, and download the image. Piping between the two
curl commands allows to use the auth cookies to get the image (
curl … --cookie-jar - | curl --cookie - …). Then attach your
test-trend.png in an “Editable Email Notification” post-build action.
Great, it worked! Almost… The image didn’t contain test results of the current build, even though the “Publish JUnit test result report” step has been executed before. I think this is the intended behavior not to include the latest build until it’s finished, but I couldn’t find any workaround to include it. To sum up, the script works great, email has an image, but without the current build.