问题
Is it possible to save “Jenkins_URL/job/JOB_Name/buildTimeGraph/png” and/or “Jenkins_URL/job/JOB_Name/test/trend” graphs as images after the job is build and them send them embedded or as attachment using a mail plugin.
like the one that shown below. http://s22.postimg.org/8619l7msx/jenkins_Graph.jpg
回答1:
I can suggest one unelegant way. The following should be done step by step inside your job:
- Download graph as png to build workspace, i.e.
wget -O time_graph.png ${JOB_URL}/buildTimeGraph/png
in a shell script build step. ${JOB_URL} is an env var set by Jenkins. Don't forget to make your job visible for anonymous otherwise download wouldn't work without authorization. - Archive downloaded png into your build's artifacts.
- Set content type to html for your email ext plugin postbuild step.
- Place
<img src="${BUILD_URL}/artifact/time_graph.png" />
into your email template body. ${BUILD_URL} is resolved by email-ext plugin to a URL to the current build. - Done.
Why need download and archiving but not just <img src="${PROJECT_URL}/buildTimeGraph/png" />
in the email body?
Because otherwise the trend img which is shown in the email will reflect the situation for the moment when it was dowloaded (cause it's generated on request) and not for the moment when email was sent. If it suits you, use the second way as it much simplier.
回答2:
Instead of using the $JOB_URL use $JOB_NAME to use the job id and reach the location.
e.g. $JOB_NAME/workspace/...
would work.
来源:https://stackoverflow.com/questions/22298036/jenkins-graphs-in-embedded-in-mail-or-as-attachment