How to set up SBT build to return zero exit code on test failure for Jenkins? -


when running specs2 tests in jenkins via sbt, build marked failure 1 test fails. since jenkins distinguishes between failure build , test failures, want change this.

i know build failure in jenkins detected exit code of call sbt, appears return 1 @ least 1 test fails.

what options have assuming want avoid changing build.sbt (or project in general) fix inconvenience?

somehow think should possible put standard sbt project standard jenkins install , have work intended.

tl;dr use testresultlogger custom test result logger doesn't throw testsfailedexception in turn sets non-0 exit code.

just noticed missed requirement "to avoid changing build.sbt. can use other *.sbt file, exitcodezero.sbt or ~/.sbt/0.13/default.sbt custom testresultlogger.

it turns out since sbt 0.13.5 there's way have such behaviour - see added setting 'testresultlogger' allows customisation of test reporting testresultlogger born.

> testresultlogger logs results after test task completes. 

as may have been read in the implementation of testresultlogger.silentwhennotests that's default value of testresultlogger:

results.overall match {   case testresult.error | testresult.failed => throw new testsfailedexception   case testresult.passed                    => } 

it means when there's issue executing tests, testsfailedexception exception thrown that's in turn caught report follows:

[error] failed: total 3, failed 1, errors 0, passed 2 [error] failed tests: [error]         helloworldspec [error] (test:test) sbt.testsfailedexception: tests unsuccessful 

my idea disable throwing exception regardless of outcome of executing tests. add following build.sbt , have exit code 0:

testresultlogger in (test, test) := new testresultlogger {     import sbt.tests._     def run(log: logger, results: output, taskname: string): unit = {         println("exit code 0...as wish")         // uncomment have default behaviour         // testresultlogger.silentwhennotests.run(log, results, taskname)     } } 

uncomment testresultlogger.silentwhennotests.run have default behaviour back.

➜  failing-tests-dont-break-build  xsbt test; echo $? java_home=/library/java/javavirtualmachines/java8/contents/home sbt_opts= -xms512m -xmx1536m -xss1m -xx:+cmsclassunloadingenabled -dfile.encoding=utf-8 [info] loading global plugins /users/jacek/.sbt/0.13/plugins [info] set current project failing-tests-dont-break-build (in build file:/users/jacek/sandbox/failing-tests-dont-break-build/) [info] helloworldspec [info] [info] 'hello world' string should [info] x contain 11 characters [error]    'hello world' doesn't have size 12 size 11 (helloworldspec.scala:7) [info] [info] + start 'hello' [info] + end 'world' [info] [info] total specification helloworldspec [info] finished in 15 ms [info] 3 examples, 1 failure, 0 error exit code 0...as wish [success] total time: 1 s, completed sep 19, 2014 9:58:09 pm 0 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -