-
-
Save letsrokk/50a3ffc8ad5af8896ce78e62fe1e8cb5 to your computer and use it in GitHub Desktop.
<!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" | |
} | |
} |
I followed step1 to step5 using Config File Provider plugin. For my project, we dont have jenkins file just job. How i can trigger this to generate summary report using jenkin job. Please let us know if any one have any suggestion to achieve this with out using jenkins file.
I haven't used jobs in a while but is there an option for Post Build Options? I think that is where you trigger it from
Yes we have post build option..I am not aware, how to trigger the execution of groovy email template file configured in config file provider plugin. If any one have any suggestions, please let us know..
Hi @pmcg86 I tried all the steps exactly you have mentioned but I am getting below error message on the email notification. Please help here. Please find error log below.
Exception raised during template rendering: Scripts not permitted to use method hudson.model.Run getResult org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method hudson.model.Run getResult at org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist.rejectMethod(StaticWhitelist.java:229) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.rejectMethod(SandboxInterceptor.java:594) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.lambda$onGetProperty$7(SandboxInterceptor.java:302) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:386) at org.kohsuke.groovy.sandbox.impl.Checker$7.call(Checker.java:375) at org.kohsuke.groovy.sandbox.GroovyInterceptor.onGetProperty(GroovyInterceptor.java:68) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:337) at org.kohsuke.groovy.sandbox.impl.Checker$7.call(Checker.java:375) at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:379) at org.kohsuke.groovy.sandbox.impl.Checker$checkedGetProperty$0.callStatic(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:55) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:197) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:233) at SimpleTemplateScript9.run(SimpleTemplateScript9.groovy:26) at hudson.plugins.emailext.groovy.sandbox.SimpleTemplateEngine$SimpleTemplate$1.writeTo(SimpleTemplateEngine.java:196) at hudson.plugins.emailext.groovy.sandbox.SimpleTemplateEngine$SimpleTemplate$1.toString(SimpleTemplateEngine.java:221) at hudson.plugins.emailext.plugins.content.ScriptContent.lambda$renderTemplate$0(ScriptContent.java:178) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:331) at hudson.plugins.emailext.plugins.content.ScriptContent.renderTemplate(ScriptContent.java:176) at hudson.plugins.emailext.plugins.content.ScriptContent.evaluate(ScriptContent.java:83) at org.jenkinsci.plugins.tokenmacro.DataBoundTokenMacro.evaluate(DataBoundTokenMacro.java:215) at org.jenkinsci.plugins.tokenmacro.Parser.processToken(Parser.java:474) at org.jenkinsci.plugins.tokenmacro.Parser.parseDelimitedToken(Parser.java:178) at org.jenkinsci.plugins.tokenmacro.Parser.parseToken(Parser.java:111) at org.jenkinsci.plugins.tokenmacro.Parser.parse(Parser.java:87) at org.jenkinsci.plugins.tokenmacro.Parser.process(Parser.java:75) at org.jenkinsci.plugins.tokenmacro.Parser.process(Parser.java:68) at org.jenkinsci.plugins.tokenmacro.TokenMacro.expand(TokenMacro.java:196) at org.jenkinsci.plugins.tokenmacro.TokenMacro.expandAll(TokenMacro.java:234) at hudson.plugins.emailext.plugins.ContentBuilder.transformText(ContentBuilder.java:88) at hudson.plugins.emailext.ExtendedEmailPublisher.addContent(ExtendedEmailPublisher.java:1080) at hudson.plugins.emailext.ExtendedEmailPublisher.createMail(ExtendedEmailPublisher.java:929) at hudson.plugins.emailext.ExtendedEmailPublisher.sendMail(ExtendedEmailPublisher.java:523) at hudson.plugins.emailext.EmailExtStep$EmailExtStepExecution.run(EmailExtStep.java:248) at hudson.plugins.emailext.EmailExtStep$EmailExtStepExecution.run(EmailExtStep.java:181) at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:829)
- groovy file I have copied as it is (point 7)
- My Jenkins file content is as below.
emailext (
attachLog: false,
body: '''${SCRIPT, template="managed:Email-Template"}''',
mimeType: 'text/html',
subject: 'Test Execution Summary',
to: 'abhi****are@.com')
Please help on this, Thanks in advance.
Hi @pmcg86 I tried all the steps exactly you have mentioned but I am getting below error message on the email notification. Please help here. Please find error log below.
Exception raised during template rendering: Scripts not permitted to use method hudson.model.Run getResult org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method hudson.model.Run getResult at org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist.rejectMethod(StaticWhitelist.java:229) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.rejectMethod(SandboxInterceptor.java:594) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.lambda$onGetProperty$7(SandboxInterceptor.java:302) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:386) at org.kohsuke.groovy.sandbox.impl.Checker$7.call(Checker.java:375) at org.kohsuke.groovy.sandbox.GroovyInterceptor.onGetProperty(GroovyInterceptor.java:68) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:337) at org.kohsuke.groovy.sandbox.impl.Checker$7.call(Checker.java:375) at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:379) at org.kohsuke.groovy.sandbox.impl.Checker$checkedGetProperty$0.callStatic(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:55) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:197) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:233) at SimpleTemplateScript9.run(SimpleTemplateScript9.groovy:26) at hudson.plugins.emailext.groovy.sandbox.SimpleTemplateEngine$SimpleTemplate$1.writeTo(SimpleTemplateEngine.java:196) at hudson.plugins.emailext.groovy.sandbox.SimpleTemplateEngine$SimpleTemplate$1.toString(SimpleTemplateEngine.java:221) at hudson.plugins.emailext.plugins.content.ScriptContent.lambda$renderTemplate$0(ScriptContent.java:178) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:331) at hudson.plugins.emailext.plugins.content.ScriptContent.renderTemplate(ScriptContent.java:176) at hudson.plugins.emailext.plugins.content.ScriptContent.evaluate(ScriptContent.java:83) at org.jenkinsci.plugins.tokenmacro.DataBoundTokenMacro.evaluate(DataBoundTokenMacro.java:215) at org.jenkinsci.plugins.tokenmacro.Parser.processToken(Parser.java:474) at org.jenkinsci.plugins.tokenmacro.Parser.parseDelimitedToken(Parser.java:178) at org.jenkinsci.plugins.tokenmacro.Parser.parseToken(Parser.java:111) at org.jenkinsci.plugins.tokenmacro.Parser.parse(Parser.java:87) at org.jenkinsci.plugins.tokenmacro.Parser.process(Parser.java:75) at org.jenkinsci.plugins.tokenmacro.Parser.process(Parser.java:68) at org.jenkinsci.plugins.tokenmacro.TokenMacro.expand(TokenMacro.java:196) at org.jenkinsci.plugins.tokenmacro.TokenMacro.expandAll(TokenMacro.java:234) at hudson.plugins.emailext.plugins.ContentBuilder.transformText(ContentBuilder.java:88) at hudson.plugins.emailext.ExtendedEmailPublisher.addContent(ExtendedEmailPublisher.java:1080) at hudson.plugins.emailext.ExtendedEmailPublisher.createMail(ExtendedEmailPublisher.java:929) at hudson.plugins.emailext.ExtendedEmailPublisher.sendMail(ExtendedEmailPublisher.java:523) at hudson.plugins.emailext.EmailExtStep$EmailExtStepExecution.run(EmailExtStep.java:248) at hudson.plugins.emailext.EmailExtStep$EmailExtStepExecution.run(EmailExtStep.java:181) at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:829)
- groovy file I have copied as it is (point 7)
- My Jenkins file content is as below.
emailext ( attachLog: false, body: '''${SCRIPT, template="managed:Email-Template"}''', mimeType: 'text/html', subject: 'Test Execution Summary', to: 'abhi****are@.com')
Please help on this, Thanks in advance.
Your JenkinFile content looks slightly different.
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"}'''
}
}
I'm assuming you masked your email by removing the provider and it's not a mistake?
Googling the first line of your error put me onto this - https://stackoverflow.com/questions/38276341/jenkins-ci-pipeline-scripts-not-permitted-to-use-method-groovy-lang-groovyobject
I'll try my best to help you but you'll need to send me over some images or the full code from your jenkins file, groovy file and plugin settings to compare against my setup
Thanks for the help with your google solution now its working fine. Actually my groovy script was not approved by Admin after approval now working fine.
Only thing is as we are using gmail the mail notification is not showing the CSS enable result, Can you please help me how can I fix this so that I will get CSS enabled result summary on Email.
I think gmail blocks any <style> tags so you might not be able to resolve it. Best thing to do for now is setup a new email with a different provider to test against.
Ok No Issues Thanks for the quick help. @pmcg86
@abhijeet-waghmare No worries. Good luck!
@pmcg86
I followed step1 to step5 using Config File Provider plugin. For my project, we dont have jenkins file just job. How i can trigger this to generate summary report using jenkin job. Please let us know if any one have any suggestion to achieve this with out using jenkins file.