Spa*_*rky 3 groovy continuous-integration jenkins email-ext
我想在Jenkins的email-ext插件中使用Groovy脚本功能,但我是新手,并且似乎有很多假设的知识.就像一开始就调用其中一个模板一样.
对此的答案可能非常明显,但我感到有些失落,并希望被指向正确的方向.
此示例基于官方的email-ext文档,遗憾的是,它没有提供有关如何$SCRIPT在Pipeline中使用代码行的任何具体示例.如果您希望使用HTML模板作为电子邮件的正文,则需要:
创建一个名为my-email.template或任何你喜欢的模板文件- 你可以在这里找到一些模板示例
<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>
Run Code Online (Sandbox Code Playgroud)让Jenkins管理员将my-email.template文件$JENKINS_HOME\email-templates放在Jenkins机器上的目录中 - 确保用户jenkins拥有此目录及其内容(即模板文件)
在管道加载中my-email.template作为主体内容:
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']]
}
Run Code Online (Sandbox Code Playgroud)