fgk*_*fgk 5 git continuous-integration jenkins email-ext jenkins-email-ext
由于 Jenkins 在我们推送到 GitHub 后自动构建所有项目,因此我们希望 Jenkins 在构建管道结束时发送电子邮件通知(无论构建是否成功)。
我使用以下脚本创建了一个共享库:
#!/usr/bin/env groovy
def call(String buildStatus = 'STARTED') {
// build status of null means successful
buildStatus = buildStatus ?: 'SUCCESS'
// Default values
def subject = "JENKINS-NOTIFICATION: ${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'"
def details = """<p>${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
<p>Check console output at "<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"</p>"""
// Send email to user who has started the build
emailext(
subject: subject,
body: details,
attachLog: true,
compressLog: true,
recipientProviders: [[$class: 'RequesterRecipientProvider'], [$class:'UpstreamComitterRecipientProvider']]
)
}
Run Code Online (Sandbox Code Playgroud)
请注意,我定义了两个recipientProviders. 据我所知,RequesterRecipientProvider应该向在 Jenkins 手动触发构建的人发送一封电子邮件,并且应该UpstreamComitterRecipientProvider向最后一次触发构建的 git 提交的人发送一封电子邮件。(来源)
在 Jenkinsfile 中,我加载了库,并在 jenkinsfile 的后块中定义了 sendNotification 命令:
#!groovy
@Library('shared-library@master') _
pipeline {
agent any
stages{
stage('Checkout code base'){
steps{
checkout scm
}
}
stage('do something'){
steps{
sh "do something"
}
}
stage('do something'){
steps{
sh "do something"
}
}
}
post{
always{
sendNotifications currentBuild.result
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当我在 Jenkins 手动触发构建时,会收到电子邮件通知,但当我推送到 GitHub 并且触发 Jenkins 构建时,不会发送电子邮件通知。这是管道的日志:
messageContentType = text/html; charset=UTF-8
Request made to attach build log
Request made to compress build log
Adding recipients from project recipient list
Sending email to upstream committer(s).
Adding recipients from trigger recipient list
Successfully created MimeMessage
An attempt to send an e-mail to empty list of recipients, ignored.
Some error occured trying to send the email...check the Jenkins log
Run Code Online (Sandbox Code Playgroud)
不幸的是,Jenkins 日志中没有更多信息。在我看来,这UpstreamComitterRecipientProvider并没有提供最后提交者的电子邮件地址。
我尝试使用DevelopersRecipientProvider,它将电子邮件发送给项目提交历史记录中的所有开发人员。这很好用。不幸的是UpstreamComitterRecipientProvider没有。
有人遇到过类似的问题吗?我错过了什么吗?
任何建议,将不胜感激。
小智 3
听起来有点像你想要的CulpritsRecipientProvider或者DevelopersRecipientProvider相反。
UpstreamComitterRecipientProvider查看上游版本,而不是当前版本。
| 归档时间: |
|
| 查看次数: |
10030 次 |
| 最近记录: |