Saikat
Saikat

Reputation: 16750

How to fail declarative Jenkins pipeline if maven tests fail?

I am running a declarative pipeline like this -

stage ('Integration Tests') {
    steps {
      bat "mvn clean verify"
    }
}

How can I fail this pipeline if integration tests fail? I have tried wrapping the step inside a script with try-catch block but that did not help. I am using JBehave Maven plugin to trigger integration tests.

Upvotes: 0

Views: 2049

Answers (2)

Saikat
Saikat

Reputation: 16750

JBehave Maven plugin has a flag ignoreFailureInStories that needed to be set as true in my case.

Upvotes: 0

mbn217
mbn217

Reputation: 914

Ok so based on my understanding you should add: -Dmaven.test.failure.ignore=false to the MAVEN_OPTS if you click on Advanced button in the Build section of your Jenkins Job.

See Maven Surefire Plugin - surefire:test options for reference.

This is due to jenkins specifies this value to true per default. Have a look at issues.jenkins-ci.org/browse/JENKINS-24655

Upvotes: 2

Related Questions