2
votes

I've got a Maven project that contains (Selenium / Cucumber) test code, run through Maven. These tests create custom ExtentReports HTML reports, which are stored in target/extentreports. This HTML report is always created (unless the project does not compile, of course).

What I'd like to accomplish is that after test execution, the contents of this folder are archived into a zip file (and preferably moved to a different folder). This should happen even if the tests fail. So, essentially, I'm looking to add something that will run no matter whether the tests run through the 'test' goal fail.

Currently, I'm running my tests through

mvn clean test

which runs the Cucumber / Selenium tests using JUnit.

I've tried a number of approaches and combinations of Maven plugins (surefire, failsafe), but I haven't found the right solution yet.

I'm running these tests through Jenkins, so any post-build Jenkins solution is fine too. I'm not sure whether installing Jenkins plugins is desirable though (we're not managing Jenkins ourselves), so solutions that do not require this would be preferred.

2

2 Answers

1
votes

A standard approach is to:

  • Make sure the build doesn't fail because of the tests:

    mvn test -Dmaven.test.failure.ignore=true

  • Add a post-build step Publish JUnit test result report which would color the build into yellow.

0
votes

Jenkins does allow for post operations

pipeline {
    agent any
    stages {
        stage('Example') {
            steps {
                echo 'Hello World'
            }
        }
    }
    post { 
        always { 
            echo 'I will always say Hello again!'
            //do your zip step here
        }
    }
}

If you are not using the declarative, then you can wrap your cucumber tests in a try catch

see https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#code-catcherror-code-catch-error-and-set-build-result

node {
    sh './set-up.sh'
    try {
        sh 'might fail'
        echo 'Succeeded!'
    } catch (err) {
        echo "Failed: ${err}"
    } finally {
        sh './tear-down.sh'
    }
    echo 'Printed whether above succeeded or failed.'
}