简体   繁体   English

如何在声明性jenkins电子邮件通知发布操作中添加git commit信息详细信息?

[英]How to add git commit information details in a declarative jenkins email notification post action?

I currently have this post action to let me know via email that the jenkins build was successful: 目前,我有此发布操作,可以通过电子邮件通知我,詹金斯构建成功:

post {
            always {
            emailext body: "${env.SITE} was deployed to ${DEPLOY_TO} with the following results: ${currentBuild.currentResult} ", subject: "Deployment results for ${env.SITE}", to: 'user@host.com,user2@host.com'
                    }
            }
}

The build is triggered once there's a new commit into the repository, so I would like to know how to include the commit hash, commit message and perhaps the commit diff for all the lines that were changed. 一旦在存储库中进行了新的提交,就会触发生成,因此我想知道如何为所有更改的行包括提交哈希,提交消息以及提交差异。 I really don't know how detailed I can get in the email. 我真的不知道我能在电子邮件中得到多少详细信息。 I haven't found anything that can get me started on this online. 我还没有找到任何可以让我从网上开始的东西。 Thank you in advance for your help! 预先感谢您的帮助!

You can use last changes plugin for that, once the plugin is installed you can use the following pipeline snippet to send an e-mail with the diff: 您可以为此使用last changes插件 ,一旦安装了插件,就可以使用以下管道代码片段发送带有diff的电子邮件:

pipeline {
    agent any
    stages {
        stage('send html diff') {
            steps {
                git 'https://github.com/YOUR_REPO.git'
                script {
                  def publisher = LastChanges.getLastChangesPublisher "PREVIOUS_REVISION", "SIDE", "LINE", true, true, "", "", "", "", ""
                  publisher.publishLastChanges()
                  def htmlDiff = publisher.getHtmlDiff()
                  writeFile file: 'build-diff.html', text: htmlDiff
                    emailext (
                      subject: "Jenkins - changes of ${env.JOB_NAME} #${env.BUILD_NUMBER}",
                      attachmentsPattern: '**/*build-diff.html',
                      mimeType: 'text/html',
                      body: """<p>See attached diff of build <b>${env.JOB_NAME} #${env.BUILD_NUMBER}</b>.</p>
                        <p>Check build changes on Jenkins <b><a href="${env.BUILD_URL}/last-changes">here</a></b>.</p>""",
                      to: "YOUR-EMAIL@gmail.com" )
                } //end script
            }
        }
    }
}

There is a section about sending the diff as e-mail on plugin docs here . 这里有一个关于在插件文档上通过电子邮件发送差异的部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM