gpt4 book ai didi

groovy - 如何在 Jenkins email-ext 插件中调用 Groovy 模板

转载 作者:行者123 更新时间:2023-12-02 07:09:17 26 4
gpt4 key购买 nike

我想在 Jenkins 的 email-ext 插件中使用 Groovy 脚本功能,但我对此很陌生,而且似乎有很多假设的知识。就像人们如何首先调用其中一个模板一样。

这个问题的答案可能很明显,但我感觉有点迷失,希望能得到正确的方向指出。

最佳答案

本示例基于官方email-ext documentation不幸的是,它没有提供任何有关如何在 Pipeline 中使用 $SCRIPT 代码行的具体示例。如果您希望使用 HTML 模板作为电子邮件正文,那么您需要:

  1. 创建一个名为 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>
  2. 让 Jenkins 管理员将 my-email.template 文件放入 Jenkins 计算机上的 $JENKINS_HOME\email-templates 目录中 - 确保用户jenkins 拥有此目录及其内容(即模板文件)

  3. 在管道中加载 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com