How do I assure that a Jenkins pipeline stage is always executed, even if a previous one failed?

天涯浪子 提交于 2019-12-23 08:26:39

问题


I am looking for a Jenkinsfile example of having a step that is always executed, even if a previous step failed.

I want to assure that I archive some builds results in case of failure and I need to be able to have an always-running step at the end.

How can I achieve this?


回答1:


   try {
         sh "false"
    } finally {

        stage 'finalize'
        echo "I will always run!"
    }



回答2:


We switched to using Jenkinsfile Declarative Pipelines, which lets us do things like this:

pipeline {
    agent any
    stages {
        stage('Test') {
            steps {
                sh './gradlew check'
            }
        }
    }
    post {
        always {
            junit 'build/reports/**/*.xml'
        }
    }
}

References:

Tests and Artifacts

Jenkins Pipeline Syntax



来源:https://stackoverflow.com/questions/37463489/how-do-i-assure-that-a-jenkins-pipeline-stage-is-always-executed-even-if-a-prev

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!