Issue
The problem is when the pipeline runs and passes I get "null" which I know "null" is a success. When a stage fails the notification properly shows "FAILURE"
Where should I be putting jenkins.currentBuild.result = CommonStrings.SUCCESS or what needs altered?
This is the method I utilize to make the curl:
def notifyTeam(String webhook2) {
jenkins.stage('Post Build Notify Teams') {
jenkins.echo "${jenkins.currentBuild.result}"
String jobName = jenkins.currentBuild.fullDisplayName
String status = jenkins.currentBuild.result
jenkins.echo "Job Name: ${jobName} STATUS: ${status}"
jenkins.sh "curl -H 'Content-Type: application/json' -d '{\"text\": \"Job Name: ${jobName} Status: ${status} URL: <${jenkins.env.BUILD_URL}>\"}' ${webhook2}"
jenkins.echo "${status}"
}
}
This is the closure pipeline:
try {
chat.prebuildChat(email, pipelineAttrs)
pipeline.run()
pipelineAttrs.getBuild().post()
} catch (e) {
jenkins.currentBuild.result = CommonStrings.FAILURE
throw e
} finally {
switch (product) {
case Product.****:
chat.notifyTeam(CommonStrings.****_WEBHOOK)
break
case Product.****:
chat.winNotifyTeam(CommonStrings.****_WEBHOOK)
break
case Product.****:
chat.notifyTeam(CommonStrings.****_WEBHOOK)
break
case Product.****:
chat.notifyTeam(CommonStrings.****_WEBHOOK)
break
case Product.****:
chat.notifyTeam(CommonStrings.****_WEBHOOK)
break
case Product.****:
chat.notifyTeam(CommonStrings.****_WEBHOOK)
break
}
chat.postbuildChat(email, pipelineAttrs)
jenkins.dir(jenkins.env.WORKSPACE) {
jenkinsUtils.cleanupWorkspace()
}
Any assistance would be greatly appreciated.
Solution
Try
String status = jenkins.currentBuild.result ?: 'SUCCESS'
Answered By - MaratC