Search code examples
jenkinsjenkins-pipelinedeclarative

Change Result in Jenkins Declarative Pipeline


I want to change the result of one of my steps in my jenkins pipeline to be UNSTABLE instead of FAILURE.

My current attempt looks like this:

steps {
  withMaven(maven: mavenTool, jdk: jdkTool) {
    sh 'mvn verify'
  }
}
post {
  failure {
    script {
      manager.build.buildUnstable()
    }
  }
}

Does anyone have experience with declarative jenkins pipelines?


Solution

  • You have to do it like this:

    steps {
      withMaven(maven: mavenTool, jdk: jdkTool) {
        sh 'mvn -Dmaven.test.failure.ignore=true verify'
    }
    post {
       always {
          junit(testResults: '**/surefire-reports/*xml', allowEmptyResults: true)
       }
    }
    

    The maven.test.failure.ignore is a config parameter of the Maven Surefire plugin.