有什么方法可以将 Jenkins 生成的更改日志导入电子邮件主题(通过默认电子邮件或email-ext 插件)?
我是 Jenkins 配置的新手,所以如果这是一个简单的问题,我深表歉意,但我无法在 email-ext 文档中找到任何内容。
我将我的 Email-ext 插件配置为使用 CHANGES 令牌(此处为官方文档):
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"
对于 HTML 消息,我在 div 中放置了相同的代码并添加了格式:
<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>
这是 Jenkins 现在发送的电子邮件中的示例屏幕截图(这个特定的提交来自 Subversion,但它对 Git 和其他版本控制系统的工作方式完全相同):
来自原始文档: 要查看所有可用电子邮件令牌的列表及其显示的内容,您可以单击“?” (问号)与项目配置屏幕上 email-ext 部分底部的 Content Token Reference 相关联。
这是结果:
${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"
不在电子邮件的主题中,但您可以使用Git Changelog 插件Jenkins
作为Job中的后期构建操作将更改日志作为邮件中的附件发送给收件人。选择Create a file
复选框,为文件命名(CHANGELOG.md
对我而言),如下图所示:
确保您已在 Jenkins JOB 中将源代码管理配置为GIT。
然后创建Editable Email Notification post build action 并将 git 更改日志文件的名称复制为 的值Attachments
,如下图所示:
从版本 2.0 及更高版本的Git Changelog Plugin开始,您可以将 changelog 作为管道中的字符串获取。然后在邮件中使用该变量。
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'
}