multibranch pieline, write mail on success (blue ocean)

14 views
Skip to first unread message

Zack Snyder

unread,
May 3, 2018, 5:54:23 AM5/3/18
to jenkins...@googlegroups.com
Hi there,
 
I want to write an email, when the build succeeded (via blue ocean).
Therefore I use the ext email plugin, however I need to build the link via groovy script, I want to add in the body text with groovy:
 
post
{
    success
    {
        script
        {
            def jobList = ${env.JOB_NAME}.tokenize("/")
            def baseJobName = jobList[0];
            jobList.removeAt(0)
            def jobRest = jobList.join("/")
        }
        
        emailext(
                 subject: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
                 body: """<p>SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
                     <p>Check console output at &QUOT;<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>&QUOT;</p>
                     <p><a href='${env.JENKINS_URL}/blue/organizations/jenkins/${baseJobName}/detail/${jobRest}/${env.BUILD_NUMBER}/pipeline'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a></p>
                     """,
                 recipientProviders: [[$class: 'DevelopersRecipientProvider']]
                )
        
    }
}
 
For unkown reason the post action will not be executed and I also do not see any logs why it failed. The log is empty.
How can I send en mail via groovy? Or what is the correct approch the scope, declarative and scripting code?
 
Can anybody help?
 
Regards,
Zack
Reply all
Reply to author
Forward
0 new messages