Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
手动取消Jenkins中的作业时,如何停止从Jenkins管道发送电子邮件_Jenkins_Groovy_Jenkins Pipeline_Pipeline - Fatal编程技术网

手动取消Jenkins中的作业时,如何停止从Jenkins管道发送电子邮件

手动取消Jenkins中的作业时,如何停止从Jenkins管道发送电子邮件,jenkins,groovy,jenkins-pipeline,pipeline,Jenkins,Groovy,Jenkins Pipeline,Pipeline,我有一个Jenkins管道,使用Groovy在构建失败或不稳定时通过电子邮件发送构建状态。但是当我在Jenkins中手动取消构建时,电子邮件仍然会发送,因为它认为这是失败的。如何使Jenkins在这种情况下不发送电子邮件?您可以使用FlowInterruptedException,例如,我的“不优雅但有效”解决方案: import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException node(){ stage("do

我有一个Jenkins管道,使用Groovy在构建失败或不稳定时通过电子邮件发送构建状态。但是当我在Jenkins中手动取消构建时,电子邮件仍然会发送,因为它认为这是失败的。如何使Jenkins在这种情况下不发送电子邮件?

您可以使用
FlowInterruptedException
,例如,我的“不优雅但有效”解决方案:

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"}
        }
    }
}
这是基于:


您可以使用
FlowInterruptedException
,例如,我的不优雅但有效的解决方案:

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"}
        }
    }
}
这是基于:


不能只说FlowInterruptedException而不说它在哪里。不能只说FlowInterruptedException而不说它在哪里。