How to send an email once a Jenkins build is complete for the master branch?

Nikhil Nambiar
1 min readAug 23, 2019

--

Use emailext plugin

TLDR; Add the following script to Jenkinsfile

post { success {   script {
if(env.BRANCH_NAME == 'master') {
emailext(subject: '${DEFAULT_SUBJECT}',
body: '${DEFAULT_CONTENT}',
to: 'this@example.com',)}
}
}

Please note this only sends an email to the recipient if the master branch build is successful.

Also note that the github variable env.BRANCH_NAME has no quotes or dollar signs to represent them.

--

--

Nikhil Nambiar
Nikhil Nambiar

No responses yet