I want to use the Groovy scripting feature in the email-ext plugin for Jenkins, but I'm new to this and there seems to be a lot of assumed knowledge. Like how one goes about invoking one of these templates in the first place.
The answer to this is probably quite obvious, but I'm feeling a bit lost and would appreciate being pointed in the right direction.
This example is based on the official email-ext documentation , which unfortunately does not provide any concrete examples on how to use the $SCRIPT
line of code in Pipeline. If you wish to use an HTML template as the body for your email then you need to:
Create a template file called my-email.template
or whatever you like - you can find some template examples here
<body> <h3>Using "build" environment variables:</h3> <p> <a href="<%= build.absoluteUrl %>"><%= build.fullDisplayName %></a> </p> <h3>List of all available "build" environment variables:</h3> <div> <% println build.properties.collect{it}.join('<br />') %> </div> </body>
Have your Jenkins administrator place the my-email.template
file inside $JENKINS_HOME\\email-templates
directory on Jenkins machine - make sure that user jenkins owns this directory as well as its content (ie template files)
In Pipeline load my-email.template
as body content:
stage('Send email') { def mailRecipients = "jenkins-user@example.com" def jobName = currentBuild.fullDisplayName emailext body: '''${SCRIPT, template="my-email.template"}''', subject: "[Jenkins] ${jobName}", to: "${mailRecipients}", replyTo: "${mailRecipients}", recipientProviders: [[$class: 'CulpritsRecipientProvider']] }
It's a pretty old thread but here's what I did to make use of the built in template do this
stage('Send Email')
{
steps
{
emailext body: '${JELLY_SCRIPT,template="html"}',recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']], subject: 'Build Successful ${JOB_NAME}',mimeType: 'text/html'
}
}
The Plugin Documentation states that the html Jelly script is built in so you can easily make use of it.
事实上,答案显而易见,并且包含在 email-ext 文档中:
${SCRIPT, template="groovy-text.template"}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.