如何在Jenkins电子邮件中包含git changelog?

时间:2011-10-14 20:08:40

标签: git email hudson jenkins changelog

有没有办法将Jenkins生成的更改日志导入电子邮件主题(通过默认电子邮件或email-ext plugin)?

我是Jenkins配置的新手,所以如果这是一个简单的问题我很抱歉,但我无法在email-ext文档中找到任何内容。

4 个答案:

答案 0 :(得分:66)

我将Email-ext插件配置为使用CHANGES令牌(official documentation here):

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;\"> &#8212; &#8220;<em>%m</em>&#8221;</div>", pathFormat="</div><div style=\"padding-left:30px;\">%p"}
</div>

以下是Jenkins现在发送的电子邮件的截图示例(此特定提交来自Subversion,但它对Git和其他版本控制系统的工作方式完全相同):

Change list for Jenkins

答案 1 :(得分:16)

从原始文档: 要查看所有可用电子邮件令牌及其显示内容的列表,您可以点击&#34;?&#34; (问号)与项目配置屏幕上email-ext部分底部的内容令牌参考相关联。

结果如下:

${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"

答案 2 :(得分:1)

不在电子邮件的主题中,但您可以使用Git Changelog Plugin作为Jenkins作业中的帖子构建操作,将更改日志作为邮件中的附件发送给收件人。选中 Create a file 复选框,为文件命名(CHANGELOG.md为我),如下图所示:

enter image description here

确保您已在Jenkins JOB中将源代码管理配置为 GIT

然后创建Editable Email Notification帖子构建操作,并将git更改日志文件的名称复制为Attachments的值,如下图所示:

enter image description here

答案 3 :(得分:1)

从版本2.0及更高版本的Git Changelog Plugin,您可以将更改日志作为管道中的字符串。然后在邮件中使用该变量。

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'
}