Reputation: 367
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
Reputation: 1469
The solution is to use the jenkins-pipeline post task with the email-ext plugin. Please refer to:
Pipeline post section: https://jenkins.io/doc/pipeline/tour/post/
Email-ext plugin: https://jenkins.io/doc/pipeline/steps/email-ext/
culprits: Sends email to the list of users who committed a change since the last non-broken build till now. This list at least always include people who made changes in this build, but if the previous build was a failure it also includes the culprit list from there.
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