I am trying to attach the template file using Jenkins pipeline, emailext. 
Variable (PROJNAME) is not accessible in the template file and I am 
receiving exceptions as an email:

*Exception raised during template rendering: No such property: env for 
class: SimpleTemplateScript21 groovy.lang.MissingPropertyException: No such 
property: env for class: SimpleTemplateScript21 at 
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
 
at 
org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52)
 
at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
 
at SimpleTemplateScript21.run(SimpleTemplateScript21.groovy:1) at 
groovy.text.SimpleTemplateEngine$SimpleTemplate$1.writeTo(SimpleTemplateEngine.java:168)
 
at 
groovy.text.SimpleTemplateEngine$SimpleTemplate$1.toString(SimpleTemplateEngine.java:180)
 
at 
hudson.plugins.emailext.plugins.content.ScriptContent.renderTemplate(ScriptContent.java:151)
 
at 
hudson.plugins.emailext.plugins.content.ScriptContent.evaluate(ScriptContent.java:82)
 
at 
org.jenkinsci.plugins.tokenmacro.DataBoundTokenMacro.evaluate(DataBoundTokenMacro.java:208)
 
at org.jenkinsci.plugins.tokenmacro.Parser.processToken(Parser.java:308) 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:68) at 
org.jenkinsci.plugins.tokenmacro.TokenMacro.expand(TokenMacro.java:204) at 
org.jenkinsci.plugins.tokenmacro.TokenMacro.expandAll(TokenMacro.java:234) 
at 
hudson.plugins.emailext.plugins.ContentBuilder.transformText(ContentBuilder.java:80)
 
at 
hudson.plugins.emailext.ExtendedEmailPublisher.addContent(ExtendedEmailPublisher.java:862)
 
at 
hudson.plugins.emailext.ExtendedEmailPublisher.createMail(ExtendedEmailPublisher.java:741)
 
at 
hudson.plugins.emailext.ExtendedEmailPublisher.sendMail(ExtendedEmailPublisher.java:451)
 
at 
hudson.plugins.emailext.EmailExtStep$EmailExtStepExecution.run(EmailExtStep.java:224)
 
at 
hudson.plugins.emailext.EmailExtStep$EmailExtStepExecution.run(EmailExtStep.java:163)
 
at 
org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47)
 
at hudson.security.ACL.impersonate(ACL.java:260) 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)*


*Pipeline Script:*
stage('Email') {
    def mailRecipients = "[email protected]"
    def jobStatus = currentBuild.currentResult
    env.PROJNAME = 'project_name'
    echo "projname is ${PROJNAME}"

    emailext body: '''${SCRIPT, template="test.template"}''',
        mimeType: 'text/html',
        subject: "[Jenkins] ${jobStatus}",
        to: "${mailRecipients}"
}

*Template (filename - test.template):*
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>Job is '${env.PROJNAME}'</p>
</body>
</html>
########################################################

Also tried replacing the variable syntax as "*${PROJNAME}*" and "*${ENV, 
var="PROJNAME"}*" but no luck. Any suggestions?

Thanks in advance.


-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/b592af0b-17dc-4173-9ac2-c6e42c3d6a1a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to