How can I assure you that the Jenkins pipeline phase is always completed, even if the previous one failed?

I am looking for an example Jenkinsfilethat a step is always executed, even if the previous step failed.

I want to assure that I archive some assembly results in the event of a failure, and I need to always have a completed step at the end.

How can i achieve this?

+4
source share
2 answers
   try {
         sh "false"
    } finally {

        stage 'finalize'
        echo "I will always run!"
    }
+4
source

We switched to using Jenkinsfile declarative pipelines, which allows us to do such things:

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

Literature:

Tests and artifacts

Jenkins Piping Syntax

+1
source

Source: https://habr.com/ru/post/1016323/


All Articles