简体   繁体   English

Jenkins管道脚本:通过发送电子邮件通知

[英]Jenkins Pipeline Script: Send Email notification through

I want to send email notifications through a Jeenkins Scripted Pipeline, when any job gets done. 我想在完成任何工作后通过Jeenkins脚本化管道发送电子邮件通知。 Email to a specific developer/group who checked into git. 通过电子邮件发送给已登录git的特定开发人员/组。 I need help with said script. 我需要有关上述脚本的帮助。

Use Email-ext plugin , configure it with docs and add similar code: 使用Email-ext插件 ,使用docs配置它,并添加类似的代码:

pipeline {
    agent any

    stages {
        stage('Build') {
            steps {
                sh "sh deploy.sh"
            }
        }
    }
    post {
        always {
            emailext body: 'Hello sainath kadaverugu', recipientProviders: [$class: 'DevelopersRecipientProvider'], subject: 'After build message'
        }
    }
}

If You want to get last committer email address checkout this thread 如果您想获得最后一个提交者的电子邮件地址,请查看此线程

EDIT : in "node-style" I used mailer 编辑 :在“节点样式”中,我使用了邮件程序

def get_mail() {
    node('master'){
        USER_MAIL = wrap([$class: 'BuildUser']) {
            return env.BUILD_USER_EMAIL
        }
    }
}

def USER_MAIL = get_mail()

node('master') {
   stage('Checkout') {
       deleteDir()
       git 'git@sometest.git'
    }

    stage('Deploy') {
        sh "sh depoly.sh"
    }
    step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: USER_MAIL, sendToIndividuals: true])
}

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

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