-->

在詹金斯的电子邮件-EXT快速测试果冻模板(Quickly testing Jelly templa

2019-08-17 04:04发布

詹金斯的电子邮件-EXT允许你写一个果冻电子邮件模板。 你如何编写和测试一个没有触发每次构建? 基本上,我正在寻找1第二次迭代,我可以修改果冻脚本,打在刷新浏览器,它会自动呈现基于硬编码的项目模板和构建结果。

Answer 1:

在_http打开詹金斯脚本控制台://服务器/脚本/(#2是有保存编辑的问题时,这是一个实际的URL)。

输入以下代码并替换your-project-name与项目的名称和me@me.com您的电子邮件地址:

import hudson.model.StreamBuildListener
import hudson.plugins.emailext.ExtendedEmailPublisher
import java.io.ByteArrayOutputStream

def projectName = "your-project-name"
def project = Jenkins.instance.getItem(projectName)

try
{

  def testing = Jenkins.instance.copy(project, "$projectName-Testing")
  def build = project.lastUnsuccessfulBuild
// see the <a href="http://javadoc.jenkins-ci.org/hudson/model/Job.html#getLastBuild()" title="Job" target="_blank">javadoc for the Job class</a> for other ways to get builds

def baos = new ByteArrayOutputStream()
def listener = new StreamBuildListener(baos)

testing.publishersList.each() { p ->
  println(p)
  if(p instanceof ExtendedEmailPublisher) {
    // modify the properties as necessary here
    p.recipientList = 'me@me.com' // set the recipient list while testing

    // run the publisher
    p.perform((AbstractBuild<?,?>)build, null, listener)
    // print out the build log from ExtendedEmailPublisher
    println(new String( baos.toByteArray(), "UTF-8" ))
  }
}

}
finally
{
    if (testing != null)
    {
        testing.delete()
    }
}

来源: https://earl-of-code.com/2013/02/prototyping-and-testing-groovy-email-templates/

还有一个跟踪使这更容易的问题:

JENKINS - 9594 -应根据以前的版本能够发送测试电子邮件



Answer 2:

现在有测试模板,对建立在较新版本的插件的选项。 如果你是一个工作的屏幕上,应该有左侧的链接,电子邮件模板测试说。 它会让你选择一个构建再次测试,它会呈现模板在那里。



文章来源: Quickly testing Jelly templates in email-ext of Jenkins