0

Consider this extract from my declarative syntax Jenkinsfile

stage("Test") {
      steps {
        sh "sh run-tests.sh"
      }
}

Even though the run-tests.sh script exit with code 1, the Jenkins job execution continues to the next step. Does anyone know what may be causing this?

EDIT: Thanks for the replies so far. I believe the problem lies elsewhere - the tests being executes are initiated by Python's nose2 library, and if I'm not mistaking it's this command that exits with 0 regardless of the status of the tests. I'll follow that lead for now and see if that solves things.

kenneho
  • 599
  • 1
  • 9
  • 17
  • 1
    Is there a reason you're nesting `sh`? You should be able to just do `sh "run-tests.sh"`. The first `sh` is a Jenkins pipeline function which should always fail if you have a non-zero return status, the second `sh` would depend on your operating system and configuration. – Michael Powers Oct 19 '18 at 13:56
  • 1
    the step should be:: sh './run-tests.sh' and the shell script should be executable – Rich Duncan Oct 19 '18 at 14:07

1 Answers1

0

I found the solution. I'm running the tests using docker-compose, and it turns out that docker-compose return 0 regardless of what my test script return. See this SO post for more info.

I added the --exit-code-from option to my docker-compose up command, and now my CI job aborts with the same exit code as my Jenkinsfile (and thus my test script).

kenneho
  • 599
  • 1
  • 9
  • 17