Jenkins email-ext,预发送脚本:如何直接用问题链接替换Jira Issue字符串?

时间:2013-08-14 13:22:10

标签: jenkins jenkins-plugins email-ext

关于email-ext的预发送脚本可能性的问题: 目前,这是电子邮件通知的“默认内容”:

<h3>$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS</h3>
<p>
Check console output at $BUILD_URL/console to view the results.
</p>
...
<hr/>
<b>Changes since last build</b><br/>
<div style="padding-left: 15px; padding-bottom: 15px;">
    ${CHANGES,format="<div><b>%a</b></div><div style=\"padding-left:30px;\"> &#8212; &#8220;<em>%m</em>&#8221;</div><br/>"}
</div>

这将包括结果电子邮件中的提交消息...并且由于我们在每次提交时都给出了Jira问题ID,因此更换Jira问题ID会很好,例如: TESTPROJECT-1234及其链接。

有人可以帮助我,实现这种行为吗? 这样做的最好方法是使用正则表达式,对吧?喜欢

    (TESTPROJECT-[1-9][0-9]*)

并将其替换为

    <a href="http://jira.server.com/browse/$1">$1</a>

但目前我没有胶水,如何使用groovy和预发送脚本来做到这一点。 :(

2 个答案:

答案 0 :(得分:0)

你甚至不需要正则表达式。请参阅此脚本示例:https://github.com/jenkinsci/email-ext-plugin/blob/master/src/main/resources/hudson/plugins/emailext/templates/groovy-html.template,其中显示了如何循环更改集。

答案 1 :(得分:0)

如果它仍然相关,则下面是发布说明的脚本,其中包含您正在寻找的链接

import hudson.model.*;
import hudson.util.*;

import java.util.regex.Pattern;
import java.util.regex.Matcher;


println build.getEnvVars()['JiraReleaseNotes']

def txt = build.getEnvVars()['JiraReleaseNotes']

def JiraReleaseNotes2 = txt.replaceAll(/# ([^]]*)/){ all, it ->
    "</br>$all"
}


def JiraReleaseNotes1 = JiraReleaseNotes2.replaceAll(/- \[([^]]*)]/){ all, it ->
    "</br><li><a href=\"http://server.com/browse/${it}\">${it}</a>"
}


println JiraReleaseNotes1

def thr = Thread.currentThread();
def currentBuild = thr.executable;

def newParamAction = new hudson.model.ParametersAction(new hudson.model.StringParameterValue("JiraReleaseNotes2", JiraReleaseNotes1 ));
currentBuild.addAction(newParamAction);