Paul
Paul

Reputation: 367

How to send email to users who has changes in jenkins build

I am using jenkins scripted pipeline. If the build fails I wish to send email to list of users who has changes(commits). I request people to help me to get the list of users and send email only to them

Upvotes: 1

Views: 1604

Answers (1)

zedv
zedv

Reputation: 1469

The solution is to use the jenkins-pipeline post task with the email-ext plugin. Please refer to:

The pipeline below should solve your problem:

Declarative Pipeline Example:

pipeline {

    agent any

    stages {
        ...
    }
    post {
        failure { 
            emailext body: "your email body here",
                     mimeType: 'text/html',
                     subject: "your subject here",
                     to: emailextrecipients([
                         [$class: 'CulpritsRecipientProvider']
                     ])
        }
    }
}

Scripted Pipeline Example:

def postFailure() {
    emailext body: "your email body here",
                     mimeType: 'text/html',
                     subject: "your subject here",
                     to: emailextrecipients([
                         [$class: 'CulpritsRecipientProvider']
                     ])
}

node {
    try {
        ...
    } catch (e) {
        postFailure()
        throw e
    }
}

Upvotes: 3

Related Questions