我想在 Jenkins 的 email-ext 插件中使用 Groovy 脚本功能,但我对此很陌生,而且似乎有很多假设的知识。就像人们如何首先调用其中一个模板一样。
这个问题的答案可能很明显,但我感觉有点迷失,希望能得到正确的方向指出。
最佳答案
本示例基于官方email-ext documentation不幸的是,它没有提供任何有关如何在 Pipeline 中使用 $SCRIPT
代码行的具体示例。如果您希望使用 HTML 模板作为电子邮件正文,那么您需要:
创建一个名为
my-email.template
的模板文件或任何您喜欢的文件 - 您可以找到一些模板示例 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>
让 Jenkins 管理员将
my-email.template
文件放入 Jenkins 计算机上的$JENKINS_HOME\email-templates
目录中 - 确保用户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']] }
关于groovy - 如何在 Jenkins email-ext 插件中调用 Groovy 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31000787/