4

我想向工作视图 中“人员”选项卡中列出的所有用户发送电子邮件通知:詹金斯工作视图

在管道工作流程中使用 Jenkins 'Mailer'帖子展示了如何在 Jenkinsfile 中发送电子邮件通知:

emailext(body: '${DEFAULT_CONTENT}', mimeType: 'text/html',
         replyTo: '$DEFAULT_REPLYTO', subject: '${DEFAULT_SUBJECT}',
         to: emailextrecipients([[$class: 'CulpritsRecipientProvider'],
                                 [$class: 'RequesterRecipientProvider']]))

我修改它以仅在构建失败或修复时发送电子邮件,灵感来自https://baptiste-wicht.com/posts/2017/06/jenkins-tip-send-notifications-fixed-builds-中的 Justin Simons 评论declarative-pipeline.html#comment-3478592834

mailNotificationAlreadySend = false

pipeline {

    ...

    stages {
    ...
    }

    post {
        changed {
            sendMailNotification()
        }
        failure {
            sendMailNotification()
        }
    }
}

void sendMailNotification() {

    if (!mailNotificationAlreadySend) {

        emailext(body: '${DEFAULT_CONTENT}', mimeType: 'text/html',
                replyTo: '$DEFAULT_REPLYTO', subject: '${DEFAULT_SUBJECT}',
                recipientProviders: [[$class: 'DevelopersRecipientProvider'],
                                     [$class: 'CulpritsRecipientProvider']]
        )

        mailNotificationAlreadySend = true
    }
}

但这只会将电子邮件发送给导致构建失败的开发人员和所有后续贡献者,直到构建结果再次成功。

应如何配置 emailext 方法以向作业视图中“人员”选项卡中列出的所有用户发送电子邮件?

我已经尝试了https://github.com/jenkinsci/email-ext-plugin/tree/master/src/main/java/hudson/plugins/emailext/plugins/recipients中所有可用的 recipientProviders,但没有任何成功。

4

0 回答 0