简体   繁体   English

从詹金斯管道发送电子邮件

[英]Sending an email from jenkins pipeline

Email sending will happen after all normal steps will finish.电子邮件发送将在所有正常步骤完成后发生。 I had trouble finding full run able snippet so sharing the one i made.我很难找到完整的可运行片段,所以分享我制作的片段。

I'm sharing this as KB - below is the answer I'm using我将其作为 KB 分享 - 以下是我正在使用的答案

- This first requires installing the plugin and configuring it (use guide in plugin) -这首先需要安装插件并对其进行配置(使用插件中的指南)

I had trouble finding full run able snippet so sharing the one i made.我很难找到完整的可运行片段,所以分享我制作的片段。

pipeline {
    agent any
    stages {
        stage('First step') {
            steps {
                // Any code you want here example:
                // sh 'ls'
            }
        }
    }
    post {
        always {
            script {
                def mailRecipients = 'xx@domain.com'
                def jobName = currentBuild.fullDisplayName
                emailext body: """
                    Email body, in HTML format.
                    </br>
                    </br>
                    <a href="${JOB_URL}/${BUILD_NUMBER}/console">Job Results</a>""",
                    mimeType: 'text/html',
                    from: 'from_this_address@domain.com',
                    subject: "Subject",
                    to: "${mailRecipients}",
                    replyTo: "${mailRecipients}",
                    recipientProviders: [[$class: 'CulpritsRecipientProvider']]
            }
        }
    }
}

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

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