onkeliroh
onkeliroh

Reputation: 1713

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?

Upvotes: 2

Views: 846

Answers (2)

Keilaron
Keilaron

Reputation: 457

Just updating this for the addition of warnError; You can now instead wrap the failing step as a warning ("unstable" build), e.g.:

 warnError('Maven tests failed!') {
   sh 'mvn verify'
 }

That way you have visibility into the failures.

Upvotes: 0

Daniel Steinmann
Daniel Steinmann

Reputation: 2199

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.

Upvotes: 2

Related Questions