How to ignore a Spock feature method in Grails 3 while running on Jenkins

It is easy to ignore a test only if the test is run in a particular environment thanks to the @IgnoreIf Spock annotation. If you run your tests in Jenkins, it is probable that the tests are being run by a user called jenkins. Thus, you can ignore a test in a Jenkins Job easily:

@Integration(applicationClass = Application.class)
@Rollback
class IntegrationSpec extends Specification {

    @IgnoreIf({ System.getProperty("user.name") == 'jenkins' })
    def "test will be ignored in jenkins"() {
        expect:
        false
    }
}

Do you like to read about Groovy/Grails development? Yes, then Subscribe to Groovy Calamari a weekly curated email newsletter about the Groovy ecosystem which I write 

Leave a Reply

Your email address will not be published. Required fields are marked *