Jenkins Pipeline Fails if Step is Unstable

前端 未结 2 1220
一个人的身影
一个人的身影 2020-12-31 01:10

Currently my pipeline fails (red), when a maven-job is unstable (yellow).

node {
    stage \'Unit/SQL-Tests\'
    parallel (
       phase1: { build \'Unit-Te         


        
2条回答
  •  孤独总比滥情好
    2020-12-31 01:56

    Lessons learned:

    • Jenkins will continuously update the pipeline according to the currentBuild.result value which can be either SUCCESS, UNSTABLE or FAILURE (source).
    • The result of build job: can be stored in a variable. The build status is in variable.result.
    • build job: , propagate: false will prevent the whole build from failing right away.
    • currentBuild.result can only get worse. If that value was previously FAILED and receives a new status SUCCESS through currentBuild.result = 'SUCCESS' it will stay FAILED

    This is what I finally used:

        node {
            def result  // define the variable once in the beginning
            stage 'Unit/SQL-Tests'
            parallel (
               phase1: { result = build job: 'Unit', propagate: false }, // might be UNSTABLE
               phase2: { build 'SQL-Tests' }
            )
            currentBuild.result = result.result  // update the build status. jenkins will update the pipeline's current status accordingly
            stage 'Install SQL'
            build 'InstallSQL'
            stage 'Deploy/Integration-Tests'
            parallel (
               phase1: { build 'Deploy' },
               phase2: { result = build job: 'Integration-Tests', propagate: false }
            )
            currentBuild.result = result.result // should the Unit-Test be FAILED and Integration-Test SUCCESS, then the currentBuild.result will stay FAILED (it can only get worse)
            stage 'Code Analysis'
            build 'Analysis'
        }
    

提交回复
热议问题