git - 如何在声明性 jenkins 电子邮件通知发布操作中添加 git 提交信息详细信息?
问题描述
我目前有这个帖子操作,通过电子邮件让我知道 jenkins 构建成功:
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'
}
}
}
一旦有新的提交进入存储库,就会触发构建,所以我想知道如何包含提交哈希、提交消息,也许还有所有已更改行的提交差异。我真的不知道我可以在电子邮件中获得多详细的信息。我还没有找到任何可以让我在网上开始的东西。预先感谢您的帮助!
解决方案
您可以为此使用最后更改插件,安装插件后,您可以使用以下管道片段发送带有差异的电子邮件:
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
}
}
}
}
在插件文档中有一个关于将差异作为电子邮件发送的部分。
推荐阅读
- entity-framework-core-3.0 - 如何从 ExecuteSqlInterpolatedAsync 获取查询结果?
- mongodb - 查询具有 n 条记录的集合
- vba - 如何使用按钮打开表单并自动为其中一个字段分配值
- npm - 由于 NPM 的身份验证问题,服务无法在 Kubernetes 上运行
- python - 未来的五月一日,使得五月一日在现在和结束之间出现两次
- apache-kafka - Kafka 消费者属性在 SCDF 上下文中设置在哪里?
- c++ - 如何导入 2 个不同的时区以检查两者是否都是星期一?
- xpath - 无法在 googlesheet 中找到要导入的正确 xpath
- linux-kernel - 为什么`pstore`不适用于三星S10 5G?
- html - 缩小窗口大小时,HTML 表格会改变颜色和格式