Search code examples
mavenjenkinsjenkins-pipelinejenkins-2

Jenkins Pipeline Fails if Step is Unstable


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

node {
    stage 'Unit/SQL-Tests'
    parallel (
       phase1: { build 'Unit-Tests' }, // maven
       phase2: { build 'SQL-Tests' } // shell
    )
    stage 'Integration-Tests'
    build 'Integration-Tests' // maven
}

In this example the job Unit-Test's result is unstable, but is shown as failed in the pipeline.

How can I change the jobs/pipeline/jenkins to have the (1) the pipeline step unstable instead of failed and (2) the pipeline's status unstable instead of failed.

I tried adding the MAVEN_OPTS parameter -Dmaven.test.failure.ignore=true, but that did not solve the issue. I am unsure how to wrap the build 'Unit-Test' into some logic that can catch and process the result.

Adding a sub-pipeline with this logic doesn't do the trick, as there is no option to checkout from subversion (that option is available in a regular maven job). I would not like to use commandline checkout if possible.


Solution

  • 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