Jenkins Pipeline Get Current Stage Status After Using catchError

前端 未结 4 1624
孤独总比滥情好
孤独总比滥情好 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:05

    As for me the most elegant way to do it, it's a post section. In your example, you mark the stage as UNSTABLE so after that you can catch it using post->unstable.

    stage("1") {
        steps {
            catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
                error 'Something goes wrong'
            }
        }
        post {
            always { echo 'Executed on every build'}
            unstable { echo 'Executed only if build is unstable (marked by catchError)'}
        }
    }
    

提交回复
热议问题