Jenkins Pipeline Get Current Stage Status After Using catchError

前端 未结 4 1661
孤独总比滥情好
孤独总比滥情好 2021-01-19 05:39

This is a follow-up to my earlier question:

Set a stage status in Jenkins Pipelines

It turns out I can keep a pipeline as SUCCESS but can mark an individual

4条回答
  •  庸人自扰
    2021-01-19 06:20

    As an alternative to add to Dibakar Aditya's answer, it is possible to wrap everything in a function which resembles regular steps. I.e.:

    stage("1") {
        def localSuccess = catchLocalError {
            // do stuff
        }
        if(!localSuccess) {
            // do something special if we're unstable
        }
    }
    
    boolean catchLocalError(Closure c) {
        try {
            c()
            return true
        } catch (Exception e) {
            return false
        }
    }
    

提交回复
热议问题