Skip to content

Instantly share code, notes, and snippets.

@letsrokk
Last active September 13, 2023 14:56
Show Gist options
  • Save letsrokk/50a3ffc8ad5af8896ce78e62fe1e8cb5 to your computer and use it in GitHub Desktop.
Save letsrokk/50a3ffc8ad5af8896ce78e62fe1e8cb5 to your computer and use it in GitHub Desktop.
Allure Summary Email using Email-ext Jenkins Plugin
<!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">&nbsp;</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"
}
}
@chunji08
Copy link

chunji08 commented Jun 3, 2020

Working now. But I am not able to see the Allure image.
temp_report

Hi @LearningNeverEnds, were you able to get the graph image in the mail ?, if yes , can you please share ?

I had the same issue as yours. and to work around, I have added this chunk in the allure-report.groovy file,

                    <tr>
                      <th>Execution History:</th>
                      <td><a
                             href="${rooturl}${build.url}allure/graph">${rooturl}${build.url}allure/graph</a></td>
                    <tr>

and this is how my email looks like now:
image

@kinoeater
Copy link

Thanks @letsrokki that was quite helpful!

@ermayank89
Copy link

ermayank89 commented Jul 23, 2020

@letsrokki @chunji08 I am still facing some issues. Let me try to explain it..
I have "Email Extension" Plugin installed on my Jenkins Server. I didn't see "email-templates" folder under $JENKINS_HOME. Hence I just created the "email-templates" manually and put "allure-report.groovy" file under $JENKINS_HOME/email-templates/allure-report.groovy..
I have the stage in my Jenkins pipeline as mentioned :
stage('Send Summary'){ emailext body: '''${SCRIPT, template="allure-report.groovy"}''', subject: "[Jenkins] Test Execution Summary", to: "all@example.com" }

I am sending this email to outlook. in the email body I see the content whatever I have put in allure-report.groovy. but not like how you mentioned in the above message

@NIk119
Copy link

NIk119 commented Jan 29, 2021

tell me how to send the report, sequentially, where to insert it ,what to change, for me it's just two pieces of code, and what to do step by step, I have not found.please explain

@cherrieg
Copy link

cherrieg commented Feb 18, 2021

hi @letsrokk, can you help me take a look why it returns null when I call AllureReportBuildAction, I added allure plugin to my jenkins, but it still doesn't work. Do I need to add one more things to jenkins?
image

@Jyoti-Netomi
Copy link

Is there a way by which we can print the test case title in the email?

@madhusudhan411994
Copy link

madhusudhan411994 commented Jun 9, 2021

hi, @letsrokk can you help me I need to add the test pass percentage and started by the user in an email report.

If I run allure-report.groovy script I can see Project Name, Build number, Date of build, and Build duration in the email I would like to see Test pass percentage and started by user or build username in the email.

image

@suraso
Copy link

suraso commented Nov 10, 2021

@madhusudhan411994
Even though its old post, I am sharing the code which has worked for me to help others.
1.For Success rate: you can use as mentioned in the original code


 <tr>
                                 <th>Success rate: </th>
                                 <td>${allureLastBuildSuccessRate}%  </td>
                        </tr>


 
  1. User name or build user: Formatted table:
      <table>
             <tbody>
                        <tr>
                                <th>Automation Suite:</th>
                                <td>${project.name}</td>
                        </tr>
                        <tr>
                                <th>Automation Cycle ID: </th>
                                <td>
                                        ${build.displayName}: (<a href="${rooturl}${build.url}">${rooturl}${build.url})</a>
                                </td>
                        </tr>
                        <tr>
                                <th>Automation Report: </th>
                                <td>
                                      <a href="${allureResultsUrl}"> ${allureResultsUrl}</a>
                                </td>
                        </tr>
                        <tr>
                                <th>Automation Date:</th>
                                <td>${it.timestampString}</td>
                        </tr>
                        <tr>
                                <th>Automation duration:</th>
                                <td>${build.durationString}</td>
                        </tr> 
                        <tr>
                                <th>Automation Started By:</th>
                        <%
                                 cause = build.getCause(hudson.model.Cause.UserIdCause.class)
                                 user_name = cause.getUserName()
                        %>
                                <td>${user_name}   </td>
                        </tr>                       
                </tbody>
        </table>

@LQJ999
Copy link

LQJ999 commented Nov 18, 2021

Exception raised during template rendering: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): Failed to create Script instance for class: class SimpleTemplateScript26. Reason: java.lang.SecurityException: Rejecting unsandboxed super constructor call: hudson.plugins.emailext.plugins.content.EmailExtScript() groovy.lang.GroovyRuntimeException: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): Failed to create Script instance for class: class SimpleTemplateScript26. Reason: java.lang.SecurityException: Rejecting unsandboxed super constructor call: hudson.plugins.emailext.plugins.content.EmailExtScript() at groovy.text.SimpleTemplateEngine.createTemplate(SimpleTemplateEngine.java:128) at groovy.text.TemplateEngine.createTemplate(TemplateEngine.java:41) at hudson.plugins.emailext.plugins.content.ScriptContent.renderTemplate(ScriptContent.java:144) at hudson.plugins.emailext.plugins.content.ScriptContent.evaluate(ScriptContent.java:81) at org.jenkinsci.plugins.tokenmacro.DataBoundTokenMacro.evaluate(DataBoundTokenMacro.java:208) at org.jenkinsci.plugins.tokenmacro.Parser.processToken(Parser.java:325) at org.jenkinsci.plugins.tokenmacro.Action$KiHW1UeqOdqAwZul.run(Unknown Source) at org.parboiled.matchers.ActionMatcher.match(ActionMatcher.java:96) at org.parboiled.parserunners.BasicParseRunner.match(BasicParseRunner.java:77) at org.parboiled.MatcherContext.runMatcher(MatcherContext.java:351) at org.parboiled.matchers.SequenceMatcher.match(SequenceMatcher.java:46) at org.parboiled.parserunners.BasicParseRunner.match(BasicParseRunner.java:77) at org.parboiled.MatcherContext.runMatcher(MatcherContext.java:351) at org.parboiled.matchers.FirstOfMatcher.match(FirstOfMatcher.java:41) at org.parboiled.parserunners.BasicParseRunner.match(BasicParseRunner.java:77) at org.parboiled.MatcherContext.runMatcher(MatcherContext.java:351) at org.parboiled.matchers.FirstOfMatcher.match(FirstOfMatcher.java:41) at org.parboiled.parserunners.BasicParseRunner.match(BasicParseRunner.java:77) at org.parboiled.MatcherContext.runMatcher(MatcherContext.java:351) at org.parboiled.matchers.ZeroOrMoreMatcher.match(ZeroOrMoreMatcher.java:39) at org.parboiled.parserunners.BasicParseRunner.match(BasicParseRunner.java:77) at org.parboiled.MatcherContext.runMatcher(MatcherContext.java:351) at org.parboiled.matchers.SequenceMatcher.match(SequenceMatcher.java:46) at org.parboiled.parserunners.BasicParseRunner.match(BasicParseRunner.java:77) at org.parboiled.MatcherContext.runMatcher(MatcherContext.java:351) at org.parboiled.parserunners.BasicParseRunner.run(BasicParseRunner.java:72) at org.parboiled.parserunners.ReportingParseRunner.runBasicMatch(ReportingParseRunner.java:86) at org.parboiled.parserunners.ReportingParseRunner.run(ReportingParseRunner.java:66) at org.parboiled.parserunners.AbstractParseRunner.run(AbstractParseRunner.java:81) at org.parboiled.parserunners.AbstractParseRunner.run(AbstractParseRunner.java:76) at org.jenkinsci.plugins.tokenmacro.Parser.process(Parser.java:85) at org.jenkinsci.plugins.tokenmacro.Parser.process(Parser.java:74) at org.jenkinsci.plugins.tokenmacro.TokenMacro.expand(TokenMacro.java:199) at org.jenkinsci.plugins.tokenmacro.TokenMacro.expandAll(TokenMacro.java:237) at hudson.plugins.emailext.plugins.ContentBuilder.transformText(ContentBuilder.java:80) at hudson.plugins.emailext.ExtendedEmailPublisher.addContent(ExtendedEmailPublisher.java:874) at hudson.plugins.emailext.ExtendedEmailPublisher.createMail(ExtendedEmailPublisher.java:747) at hudson.plugins.emailext.ExtendedEmailPublisher.sendMail(ExtendedEmailPublisher.java:451) at hudson.plugins.emailext.EmailExtStep$EmailExtStepExecution.run(EmailExtStep.java:236) at hudson.plugins.emailext.EmailExtStep$EmailExtStepExecution.run(EmailExtStep.java:174) at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47) at hudson.security.ACL.impersonate(ACL.java:367) at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

Hi @dmitry Mayer, I am send email to outlook arise issue , how ? Looking forward to your reply ,thank you

@pmcg86
Copy link

pmcg86 commented May 27, 2022

Has anyone got a solution for showing images in the email from the trends? The below code doesn't work

<div>
	<img lazymap="${allureResultsUrl}/graphMap" src="${allureResultsUrl}/graph" alt="Allure results trend"/>
	</br>
</div>

@kartnan
Copy link

kartnan commented May 27, 2022

@pmcg86

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.

@imtiyaz081
Copy link

imtiyaz081 commented Jun 1, 2022

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 '
	   }
    }
		 		   			
  

}		

@imtiyaz081
Copy link

Hi Friends plz help,
m able to generate allure result but not able to publish it in email plz help

@pmcg86
Copy link

pmcg86 commented Jun 1, 2022

Hi Friends plz help, m able to generate allure result but not able to publish it in email plz help

  1. Install a plugin called Config File Provider Plugin.
  2. When installed go to Dashboard -> Manage Jenkins -> Manage Files -> Add New Config File
  3. Click on the Extended Email Publisher Groovy Template radio then Next.
  4. Add a name and copy it also for later
  5. Add the HTML in Point 7 to the Content section and click on Submit.
  6. Add the 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. (This is found in Manage Jenkins -> Configure System) - You can also do this by adding a flag to the jenkinsfile for your post conditions - mimeType: 'text/html'

@gmook9
Copy link

gmook9 commented Jul 26, 2022

@letsrokk now i have something like this image after attaching that as a default content :/

Did you ever fix this?

@pmcg86
Copy link

pmcg86 commented Jul 27, 2022

Yeah mine works fine. Did you try copying mine exactly first?

image

@gmook9
Copy link

gmook9 commented Jul 27, 2022

Yeah mine works fine. Did you try copying mine exactly first?

image

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

@pmcg86
Copy link

pmcg86 commented Jul 28, 2022

Yeah mine works fine. Did you try copying mine exactly first?
image

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

@saritha-bh
Copy link

@letsrokk now i have something like this image after attaching that as a default content :/

Did you ever fix this?

Hi,
Even i am getting similar kind of issue , expressions are not getting evaluated , can some one help
image

@CarrieSun
Copy link

CarrieSun commented Sep 22, 2022

Using the following code,
lazymap="${allureResultsUrl}/graphMap" src="${allureResultsUrl}/graph" alt="Allure results trend"
This picture can be displayed in the email 。
I want to show more other pictures in Allure report, like other pictures in ${allureResultsUrl}/# , Does it have some function urls that can be called ?

@CarrieSun
Copy link

Can I call these functions through python script in Jenkins' workspace ?
build.getAction(ru.yandex.qatools.allure.jenkins.AllureReportBuildAction.class)
build.getAction(ru.yandex.qatools.allure.jenkins.AllureBuildAction.class)

@ravibabu101143
Copy link

ravibabu101143 commented Nov 10, 2022

@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.

@pmcg86
Copy link

pmcg86 commented Nov 10, 2022

@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.

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

@ravibabu101143
Copy link

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..

@abhijeet-waghmare
Copy link

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)

  1. groovy file I have copied as it is (point 7)
  2. 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.

@pmcg86
Copy link

pmcg86 commented Sep 13, 2023

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)

  1. groovy file I have copied as it is (point 7)
  2. 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

@abhijeet-waghmare
Copy link

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.
Screenshot 2023-09-13 at 7 49 46 PM

@pmcg86
Copy link

pmcg86 commented Sep 13, 2023

@abhijeet-waghmare

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.

@abhijeet-waghmare
Copy link

Ok No Issues Thanks for the quick help. @pmcg86

@pmcg86
Copy link

pmcg86 commented Sep 13, 2023

@abhijeet-waghmare No worries. Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment