如何在 Jenkins 电子邮件中包含 git 变更日志?

发布于 2024-12-09 22:45:03 字数 227 浏览 0 评论 0 原文

有没有办法将 Jenkins 生成的变更日志导入到电子邮件的主题(通过默认电子邮件,或者 电子邮件分机插件)?

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

Is there any way to import the changelog that is generated by Jenkins to the subject of an email (either through the default email, or the email-ext plugin)?

I am new to Jenkins configuration, so I apologize if this is a simple issue, but I was not able to find anything on the email-ext documentation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

水波映月 2024-12-16 22:45:03

我将我的 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 现在发出的电子邮件中的示例屏幕截图(此特定提交来自来自颠覆,但是它对于 Git 和其他版本控制系统的工作原理完全相同):

Jenkins 的更改列表

I configured my Email-ext plug-in to use the CHANGES Token (official documentation here):

Changes:
${CHANGES, showPaths=true, format="%a: %r %p \n--\"%m\"", pathFormat="\n\t- %p"}

That prints the following in my build notifications:

Changes:
Username: 123
    - Project/Filename1.m
    - Project/Filename2.m
    -- "My log message"

For HTML messages, I placed the same code within a div and added formatting:

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

Here's a sample screenshot of how it looks in the e-mails sent out by Jenkins now (this particular commit came from Subversion, but it works exactly the same for Git and other version control systems):

Change list for Jenkins

千仐 2024-12-16 22:45:03

来自原始文档:
要查看所有可用电子邮件令牌及其显示内容的列表,您可以单击“?” (问号)与项目配置屏幕上 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"

From original documentation:
To see a list of all available email tokens and what they display, you can click the "?" (question mark) associated with the Content Token Reference at the bottom of the email-ext section on the project configuration screen.

Here is result:

${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"
残月升风 2024-12-16 22:45:03

不在电子邮件主题中,但您可以使用 Git Changelog 插件 作为 Jenkins 作业中的构建后操作。选择创建文件复选框,为文件命名(对我来说是CHANGELOG.md),如下图所示:

在此处输入图像描述

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

然后创建 可编辑电子邮件通知 构建后操作并复制名称git 更改日志文件的值作为 Attachments 的值,如下图所示:

在此处输入图像描述

Not in the subject of an email though you can send the change log to the recipient as an attachment in a mail using Git Changelog Plugin as post build action in Jenkins Job. Select Create a file checkbox, give a name to a file (CHANGELOG.md for me), as in below image:

enter image description here

Make sure you have configured Source Code Management as GIT in Jenkins JOB.

Then create Editable Email Notification post build action and copy the name of the git change log file as the value of Attachments, as in below image:

enter image description here

梦中的蝴蝶 2024-12-16 22:45:03

Git Changelog Plugin 2.0 及更高版本中,您可以获取字符串形式的变更日志在管道中。然后只需在邮件中使用该变量即可。

node {
 deleteDir()
 sh """
 git clone [email protected]: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'
}

From version 2.0 and later of Git Changelog Plugin, you can get the changelog as a string in a pipeline. And then just use that variable in the mail.

node {
 deleteDir()
 sh """
 git clone [email protected]: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'
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文