I have a Jenkins pipeline using Groovy to send the status of the builds via emails when it is failure or unstable. But when i cancel the build manually in Jenkins, the email still send because it take that as a failure. How can i make Jenkins not to send emails in this situation?
Asked
Active
Viewed 802 times
1 Answers
-1
You can play with the FlowInterruptedException
, for example, my not graceful, but working solution:
import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
node(){
stage("doing things"){
sendEmailflag = true
try{
echo "into try block"
sleep 10
}
catch(org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
sendEmailflag = false
echo "!!!caused error $e"
throw e
}
finally{
if(sendEmailflag == false)
{echo "do not send e-mail"}
else
{echo "send e-mail"}
}
}
}
this is based on:
Abort current build from pipeline in Jenkins

Sysanin
- 1,501
- 20
- 27
-
Can't just say FlowInterruptedException without saying where that is. – Philip Rego Apr 02 '19 at 18:28