9
votes

I'm setting up a Jenkins pipeline wherein I want to send post build notification to more than one receipents. i'm not able to find how to set "CC", Can someone help.

An example of my pipeline is as under:

pipeline {
    agent any
    stages {
        stage('No-op') {
            steps {
                sh 'ls'
            }
        }
    }
    post {
        failure {
        mail to: '[email protected]',
             subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
             body: "Something is wrong with ${env.BUILD_URL}"
    }
}

}

The above example is working fine for me, but i want to modify the following line to send notification to multiple people (preferably in CC):

mail to: '[email protected]',

I'm using Jenkins ver. 2.41

5
what the plugin do you use?slesh
Plugin for what? I have the standard installation of Jenkins ver. 2.41Yash

5 Answers

14
votes

I don't know if you can CC them, but to send to multiple recipients try using a comma-delimited list:

mail to: '[email protected],[email protected]',
6
votes

Use Snippet generator to explore more options regarding most of the steps. You can CC or even BCC like:

Pipeline Command :

mail bcc: '[email protected]', body: 'Test CC Pipeline', cc: '[email protected]', from: '', replyTo: '', subject: 'Testing CC', to: '[email protected]'
4
votes

For the emailext script, use cc within to section as below:

emailext body: 'testing',subject: 'testing', to: '[email protected],cc:[email protected]'

reference: https://issues.jenkins-ci.org/plugins/servlet/mobile#issus/JENKINS-6703

1
votes

For scripted pipeline:

mail bcc: '', body: 'Build Report', cc: '', from: '', replyTo: '', subject: 'Build Finished', to: '[email protected],[email protected]'
0
votes

I also had trouble with 'cc:' failing to send out emails. I used the 'to:' line and specified multiple users. You can do this with variables as well, if you have a list of emails you want to pull in. For example, I declared primaryOwnerEmail and secondaryOwners [list of emails] and pulled them in the 'to:' line below.

stage ("Notify Developers of Success"){
    env.ForEmailPlugin = env.WORKSPACE
    emailext attachmentsPattern: 'Checkmarx\\Reports\\*.pdf',
     to: "${primaryOwnerEmail},${secondaryOwners}",
     subject: "${env.JOB_NAME} - (${env.BUILD_NUMBER}) Finished Successfuly!",
     body: "Check console output at  ${env.BUILD_URL} to view the results"
}