Jenkins Pipeline Fails if Step is Unstable

本秂侑毒 提交于 2019-11-30 08:26:22
Tim

Whatever the step is UNSTABLE or FAILED, the final build result in your script will be FAILED.

You can add propagate to false by default to avoid fail the flow.

def result = build job: 'test', propagate: false

In the end of the flow, you can verdict the final result based on what you got from the "result" variable.

For example

currentBuild.result='UNSTABLE'

Here is a detail example How to set current build result in Pipeline

Br,

Tim

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: <JOBNAME> can be stored in a variable. The build status is in variable.result.
  • build job: <JOBNAME>, 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'
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!