<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> | |
<style type="text/css"> | |
/*base css*/ | |
body | |
{ | |
margin: 0px; | |
padding: 15px; | |
} | |
body, td, th | |
{ | |
font-family: "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, Tahoma, sans-serif; | |
font-size: 10pt; | |
} | |
th | |
{ | |
text-align: left; | |
} | |
h1 | |
{ | |
margin-top: 0px; | |
} | |
a | |
{ | |
color:#4a72af | |
} | |
/*div styles*/ | |
.status{background-color:<%= | |
build.result.toString() == "SUCCESS" ? 'green' : 'red' %>;font-size:28px;font-weight:bold;color:white;width:720px;height:52px;margin-bottom:18px;text-align:center;vertical-align:middle;border-collapse:collapse;background-repeat:no-repeat} | |
.status .info{color:white!important;text-shadow:0 -1px 0 rgba(0,0,0,0.3);font-size:32px;line-height:36px;padding:8px 0} | |
</style> | |
<body> | |
<div class="content round_border"> | |
<div class="status"> | |
<p class="info">The build <%= build.result.toString().toLowerCase() %></p> | |
</div> | |
<!-- status --> | |
<table> | |
<tbody> | |
<tr> | |
<th>Project:</th> | |
<td>${project.name}</td> | |
</tr> | |
<tr> | |
<th>Build ${build.displayName}:</th> | |
<td><a | |
href="${rooturl}${build.url}">${rooturl}${build.url}</a></td> | |
</tr> | |
<tr> | |
<th>Date of build:</th> | |
<td>${it.timestampString}</td> | |
</tr> | |
<tr> | |
<th>Build duration:</th> | |
<td>${build.durationString}</td> | |
</tr> | |
<tr> | |
<td colspan="2"> </td> | |
</tr> | |
</tbody> | |
</table> | |
<!-- main --> | |
<% def artifacts = build.artifacts | |
if(artifacts != null && artifacts.size() > 0) { %> | |
<b>Build Artifacts:</b> | |
<ul> | |
<% artifacts.each() { f -> %> | |
<li><a href="${rooturl}${build.url}artifact/${f}">${f}</a></li> | |
<% } %> | |
</ul> | |
<% } %> | |
<!-- artifacts --> | |
<% | |
lastAllureReportBuildAction = build.getAction(ru.yandex.qatools.allure.jenkins.AllureReportBuildAction.class) | |
lastAllureBuildAction = build.getAction(ru.yandex.qatools.allure.jenkins.AllureBuildAction.class) | |
if (lastAllureReportBuildAction) { | |
allureResultsUrl = "${rooturl}${build.url}allure" | |
allureLastBuildSuccessRate = String.format("%.2f", lastAllureReportBuildAction.getPassedCount() * 100f / lastAllureReportBuildAction.getTotalCount()) | |
} | |
%> | |
<% if (lastAllureReportBuildAction) { %> | |
<h2>Allure Results</h2> | |
<table> | |
<tbody> | |
<tr> | |
<th>Total Allure tests run:</th> | |
<td><a href="${allureResultsUrl}">${lastAllureReportBuildAction.getTotalCount()}</a></td> | |
</tr> | |
<tr> | |
<th>Failed:</th> | |
<td>${lastAllureReportBuildAction.getFailedCount()} </td> | |
</tr> | |
<tr> | |
<th>Passed:</th> | |
<td>${lastAllureReportBuildAction.getPassedCount()} </td> | |
</tr> | |
<tr> | |
<th>Skipped:</th> | |
<td>${lastAllureReportBuildAction.getSkipCount()} </td> | |
</tr> | |
<tr> | |
<th>Broken:</th> | |
<td>${lastAllureReportBuildAction.getBrokenCount()} </td> | |
</tr> | |
<tr> | |
<th>Success rate: </th> | |
<td>${allureLastBuildSuccessRate}% </td> | |
</tr> | |
</tbody> | |
</table> | |
<img lazymap="${allureResultsUrl}/graphMap" src="${allureResultsUrl}/graph" alt="Allure results trend"/> | |
<% } %> | |
<!-- content --> | |
<!-- bottom message --> | |
</body> |
node { | |
stage('Test') { | |
//... test execution steps | |
} | |
stage('Build report'){ | |
allure includeProperties: false, jdk: '', results: [[path: 'target/allure-results']] | |
} | |
stage('Send Summary'){ | |
emailext body: '''${SCRIPT, template="allure-report.groovy"}''', | |
subject: "[Jenkins] Test Execution Summary", | |
to: "all@example.com" | |
} | |
} |
It will not work. The email-template code does not have permissions to access that allure trend graph. So you need to use basic authentication.
Have the username password for your jenkins machine like this username:password Encode this to base64.
<%
String authHeaderValue = "Basic " + "<base64 encoded credentials>";
content=new URL("${allureResultsUrl}/graph").getBytes( useCaches: true, allowUserInteraction: false, requestProperties: ["User-Agent": "Groovy Sample Script", "Authorization": authHeaderValue, "Content-Type": "image/png"])
%>
Then convert the whole image to base64 and use it like the following.
<img src="data:image/png;base64, ${content.encodeBase64().toString()}"/>
This works for me.
pipeline {
agent any
stages {
stage("scm checkout") {
steps {
git branch: 'feature/wdio', credentialsId: '*******************', url: 'https://git.jamesavery.com/ecom/ecom_qa_automation.git'
}
}
stage('install dependencies') {
steps {
sh 'npm install --save'
}
}
stage('Run Automattion') {
steps {
echo 'run automation'
browserstack('26fd35b3-01ee-4253-912d-a1c7102c0f51') {
// some block
sh 'ENV=bld npm run local-desktopBstack'
}
}
}
}
post {
always {
allure includeProperties: false, jdk: '', results: [[path: 'src/allure-results']]
emailext attachLog: true, body: 'Automation test done on Build # $BUILD_NUMBER - $BUILD_STATUS, Allura report url:https://jenkins.jamesavery.com/job/jac-test2/$BUILD_NUMBER/allure!', compressLog: true, subject: 'JAC Automation Test Result', to: 'imtiyaz081@gmail.com '
}
}
}
Hi Friends plz help,
m able to generate allure result but not able to publish it in email plz help
Hi Friends plz help, m able to generate allure result but not able to publish it in email plz help
- Install a plugin called Config File Provider Plugin.
- When installed go to Dashboard -> Manage Jenkins -> Manage Files -> Add New Config File
- Click on the Extended Email Publisher Groovy Template radio then Next.
- Add a name and copy it also for later
- Add the HTML in Point 7 to the Content section and click on Submit.
- Add the other below content into your jenkins file
always {
allure jdk: '', results: [[path: 'allure-results']]
archiveArtifacts(artifacts: '**/TestCaptures/*.png', allowEmptyArchive: true, caseSensitive: false)
}
success {
echo "SUCCESS"
emailext to:'youremailhere',
subject: env.JOB_NAME,
body: '''${SCRIPT, template="managed:groovy-email-template"}'''
}
unstable {
echo "UNSTABLE"
emailext to:'youremailhere',
subject: env.JOB_NAME,
body: '''${SCRIPT, template="managed:groovy-email-template"}'''
}
failure {
echo "FAILURE"
emailext to:'youremailhere',
subject: env.JOB_NAME,
body: '''${SCRIPT, template="managed:groovy-email-template"}'''
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<style type="text/css">
body {
margin: 0px;
padding: 15px;
}
body, td, th {
font-family: "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, Tahoma, sans-serif;
font-size: 10pt;
}
th {
text-align: left;
padding-left: 5px;
}
.section {
width: 50%;
border: thin black solid;
}
.status {
background-color:<%= build.result.toString() == "SUCCESS" ? 'green' : 'red' %>;
font-size:24px;
font-weight:bold;
color:white!important;
width:720px;
height:52px;
text-align:center;
vertical-align:middle;
border-collapse:collapse;
background-repeat:no-repeat;
}
</style>
<body>
<!-- BUILD RESULT -->
<table class="section">
<div>
<td class="status" colspan="2">${build.result}</td>
</div>
<tr>
<th>URL:</th>
<td><a href="${rooturl}${build.url}">${rooturl}${build.url}</a></td>
</tr>
<tr>
<th>Date:</th>
<td>${it.timestampString}</td>
</tr>
<tr>
<th>Duration:</th>
<td>${build.durationString}</td>
</tr>
<tr>
<th>Cause:</th>
<td><% build.causes.each() { cause -> %> ${cause.shortDescription} <% } %></td>
</tr>
</table>
<br/>
<!-- ALLURE REPORT -->
<%
lastAllureReportBuildAction = build.getAction(ru.yandex.qatools.allure.jenkins.AllureReportBuildAction.class)
lastAllureBuildAction = build.getAction(ru.yandex.qatools.allure.jenkins.AllureBuildAction.class)
if (lastAllureReportBuildAction) {
allureResultsUrl = "${rooturl}${build.url}allure"
allureLastBuildSuccessRate = String.format("%.2f", lastAllureReportBuildAction.getPassedCount() * 100f / lastAllureReportBuildAction.getTotalCount())
}
if (lastAllureReportBuildAction) {
%>
<table class="section">
<div>
<td class="status" colspan="2">ALLURE TEST RESULTS</td>
</div>
<tr>
<th>Total Tests:</th>
<td><a href="${allureResultsUrl}">${lastAllureReportBuildAction.getTotalCount()}</a></td>
</tr>
<tr>
<th>Failed:</th>
<td>${lastAllureReportBuildAction.getFailedCount()}</td>
</tr>
<tr>
<th>Passed:</th>
<td>${lastAllureReportBuildAction.getPassedCount()}</td>
</tr>
<tr>
<th>Skipped:</th>
<td>${lastAllureReportBuildAction.getSkipCount()}</td>
</tr>
<tr>
<th>Broken:</th>
<td>${lastAllureReportBuildAction.getBrokenCount()}</td>
</tr>
<tr>
<th>Success Rate: </th>
<td>${allureLastBuildSuccessRate}% </td>
</tr>
</table>
</br>
<% } %>
<!-- ALLURE IMAGE -->
<div>
<img lazymap="${allureResultsUrl}/graphMap" src="${allureResultsUrl}/graph" alt="Allure results trend"/>
</br>
</div>
<!-- ARTIFACTS -->
</br>
<div>
<% def artifacts = build.artifacts
if(artifacts != null && artifacts.size() > 0) { %>
<b>Build Artifacts:</b>
<ul>
<% artifacts.each() { f -> %>
<li><a href="${rooturl}${build.url}artifact/${f}">${f}</a></li>
<% } %>
</ul>
<% } %>
</div>
</body>
8.Check if email is working now. If not, you might need to install Email Extension plugin. If you need to install Email Extention make sure to change the Default Content Type to HTML. You can also do this by adding a flag to the jenkinsfile for your post conditions - mimeType: 'text/html'
@letsrokk now i have something like this
after attaching that as a default content :/
Did you ever fix this?
Yeah mine works fine. Did you try copying mine exactly first?
I am not sure where to put the Jenkins file. How does that differ from putting that script in say a pipeline?
If I could just find the JENKINS_HOME/email-templates this would be easier but I cannot find it
If you don't have the email-templates folder you need to create it yourself
Has anyone got a solution for showing images in the email from the trends? The below code doesn't work