有没有办法将Jenkins生成的更改日志导入电子邮件主题(通过默认电子邮件或email-ext插件)?
我对Jenkins配置还很陌生,所以如果这是一个简单的问题,我很抱歉,但我在email-ext文档中找不到任何信息。
我配置了我的Email-ext插件以使用CHANGES Token(官方文档在此):
Changes:
${CHANGES, showPaths=true, format="%a: %r %p \n--\"%m\"", pathFormat="\n\t- %p"}
Changes:
Username: 123
- Project/Filename1.m
- Project/Filename2.m
-- "My log message"
<div style="padding-left: 30px; padding-bottom: 15px;">
${CHANGES, showPaths=true, format="<div><b>%a</b>: %r %p </div><div style=\"padding-left:30px;\"> — “<em>%m</em>”</div>", pathFormat="</div><div style=\"padding-left:30px;\">%p"}
</div>
根据原始文档:
要查看所有可用的电子邮件令牌及其显示内容列表,您可以单击项目配置屏幕上的电子邮件扩展部分底部与内容令牌参考相关联的“?”(问号)。这里是结果:
${CHANGES}
Displays the changes since the last build.
showDependencies
If true, changes to projects this build depends on are shown. Defaults to false
showPaths
If true, the paths, modifued by a commit are shown. Defaults to false
format
For each commit listed, a string containing %X, where %x is one of:
%a
author
%d
date
%m
message
%p
path
%r
revision
Not all revision systems support %d and %r. If specified showPaths argument is ignored. Defaults to "[%a] %m\\n"
pathFormat
A string containing %p to indicate how to print paths. Defaults to "\\t%p\\n"
node {
deleteDir()
sh """
git clone git@github.com:jenkinsci/git-changelog-plugin.git .
"""
def changelogString = gitChangelog returnType: 'STRING',
from: [type: 'REF', value: 'git-changelog-1.50'],
to: [type: 'REF', value: 'master'],
template: """
<h1> Git Changelog changelog </h1>
<p>
Changelog of Git Changelog.
</p>
{{#tags}}
<h2> {{name}} </h2>
{{#issues}}
{{#hasIssue}}
{{#hasLink}}
<h2> {{name}} <a href="{{link}}">{{issue}}</a> {{title}} </h2>
{{/hasLink}}
{{^hasLink}}
<h2> {{name}} {{issue}} {{title}} </h2>
{{/hasLink}}
{{/hasIssue}}
{{^hasIssue}}
<h2> {{name}} </h2>
{{/hasIssue}}
{{#commits}}
<a href="https://github.com/tomasbjerre/git-changelog-lib/commit/{{hash}}">{{hash}}</a> {{authorName}} <i>{{commitTime}}</i>
<p>
<h3>{{{messageTitle}}}</h3>
{{#messageBodyItems}}
<li> {{.}}</li>
{{/messageBodyItems}}
</p>
{{/commits}}
{{/issues}}
{{/tags}}
"""
mail bcc: '', body: """Here is the changelog:
${changelogString}
""", cc: '', from: '', replyTo: '', subject: 'The Changelog', to: 'the@email'
}
虽然不能在邮件主题中添加更改日志,但是您可以使用Git Changelog Plugin作为Jenkins
作业的后续构建操作,在邮件中以附件的形式将更改日志发送给收件人。选择创建文件
复选框,为文件命名(例如CHANGELOG.md
),如下图所示:
请确保您已在Jenkins JOB中配置了源代码管理为GIT。
然后创建可编辑邮件通知构建后操作,并将git更改日志文件的名称复制为Attachments
的值,如下图所示: