Lucas Carneiro
Lucas Carneiro

Reputation: 570

How can I make a Jenkins build fail only for specific tests?

I have an application which has unit and integration tests. Inside Jenkins, only unit tests are being called, and if any of them fail, the build will fail as well. Integration tests are not being called because some of them depend on external servers, which can be offline in the moment of a new build, thus making the build fail. Is it possible to run these tests on Jenkins without failing the build? If so, how should I configure it?

Just to make clear, the expected behavior is:

Upvotes: 1

Views: 549

Answers (2)

lichensky
lichensky

Reputation: 66

If you are using pipeline you can use try-catch block:

node {
    stage('Unit') {
        // run unit tests
    }

    stage('Integration') {
        try {
            // run integration tests
        } catch (e) {
            // ignore
        } finally {
            // archive test results
        }
    }

}

Upvotes: 1

kalou.net
kalou.net

Reputation: 466

one very simple way is to put "exit 0" at the end of the tests relying on external servers.

for example using a unix shell script you may write:

#!/bin/bash

# If remote check fails, exit with rc=0

./my_remote_server_check1 || exit 0

Upvotes: 0

Related Questions