0

我有一些非常奇怪的事情发生。

我使用 jenkins 脚本化管道发送带有电子邮件分机插件和模板 groovy-html.template 的电子邮件。如果变更集为空或构建结果失败,则电子邮件会正确发送,但如果构建结果在(SUCCESS,UNSTABLE)并且变更集不为空,我永远不会收到电子邮件......我查看了所有詹金斯日志并且没有发现任何可以解释这种行为的错误。电子邮件模板 jelly html 或 groovy 文本也会出现此问题。

知道为什么我会出现这种行为吗?

这是我的代码片段:

emailext(
        subject: 'Deployment',
        body: '${SCRIPT, template="groovy-html.template"}',
        to: 'email@address.com')

这是完整的管道

4

1 回答 1

0

您想尝试使用声明性管道吗?

更改此部分

node('master') {
    checkout(scm: [$class: 'GitSCM', 
        branches: [[name: "*/develop"]],
        extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'repo1']], 
        userRemoteConfigs: [[credentialsId: 'bitbucket.jenkins', 
        url: 'urlToRepo.git']]],
        changelog: true, poll: true)

    showChangeLogs()

    //currentBuild.result = 'FAILURE'

    emailext(
        subject: 'Deployment',
        body: '${SCRIPT, template="groovy-html.template"}',
        to: 'email@address.com')
}

通过这个

pipeline {
    agent any
    stages {
        stage('master') {
            steps {
                script {
                    checkout(scm: [$class: 'GitSCM', 
                        branches: [[name: "*/develop"]],
                        extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'repo1']], 
                        userRemoteConfigs: [[credentialsId: 'bitbucket.jenkins', 
                        url: 'urlToRepo.git']]],
                        changelog: true, poll: true)

                    showChangeLogs()

                    //currentBuild.result = 'FAILURE'

                }
            }
        }
    }
    post { 
        always { 
            emailext(
                subject: 'Deployment',
                body: '${SCRIPT, template="groovy-html.template"}',
                to: 'email@address.com')
        }
    }
}
于 2020-01-20T19:18:28.317 回答