sbt exit code?

995 views
Skip to first unread message

Brice Figureau

unread,
Jul 3, 2013, 11:45:14 AM7/3/13
to simple-b...@googlegroups.com
Hi,

I'm running sbt through a shell task in a jenkins job with the following
command-line:

sbt [uninteresting options] clean compile test cucumber

So, if the compilation fails, then sbt exits with a non-zero exit code,
and the build is marked as failed in Jenkins. Fine, that's exactly what
I want.

If the compilation succeeds but one of the test fails, then sbt will
also exit with a non-zero status code without trying to run the cucumber
task which is afterward. It also fully fails the build.

I'd like to have a way to tell sbt to not exit with a non-zero exit code
if a test fails, so that I can mark the build as unstable (instead of
failed). Moreover if I could make sure the cucumber task is run
independently of having test failure that'd be awesome.

Is there a way to do that through sbt configuration?

Thanks!
--
Brice Figureau
My Blog: http://www.masterzen.fr/

Harald Meland

unread,
Jul 4, 2013, 3:39:29 AM7/4/13
to simple-b...@googlegroups.com
Others will probably give more information on if/how this can be done
through sbt configuration, but why not do it externally to sbt, in the
Jenkins shell script command -- something along the lines of:

if sbt [options] clean compile; then
if sbt [options] test; then :
else
# somehow mark build as unstable
fi

sbt [options] cucumber
else
exit 1
fi

?
> --
> You received this message because you are subscribed to the Google Groups "simple-build-tool" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to simple-build-t...@googlegroups.com.
> To post to this group, send email to simple-b...@googlegroups.com.
> Visit this group at http://groups.google.com/group/simple-build-tool.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Harald

Mark Harrah

unread,
Jul 8, 2013, 3:13:53 PM7/8/13
to simple-b...@googlegroups.com
Consider writing a custom task that runs `test` and `cucumber` and handles their failure.

As an example using 0.13 syntax[1] (for clarity, but see also the 0.12 syntax[2]):

lazy val ciTests = taskKey[Unit]("Run tests for CI")

ciTests := {
val testResult = (test in Test).result.value
val cucumberResult = (cucumber in Test).result.value
...
}

The .result call makes the task return Result[T] instead of T. (For test, T is Unit.) Result [3] is similar to Either, with failure information in Inc and a success in Value. By using the tasks via .result, `ci` won't fail if test or cucumber fail. Instead, you can inspect whether they failed or succeeded and continue or fail as desired.

sbt executes inputs in parallel, so the above will run cucumber and test simultaneously (unless cucumber separately depends on test).

-Mark

[1] http://www.scala-sbt.org/0.13.0/docs/Detailed-Topics/Tasks.html#handling-failure
[2] http://www.scala-sbt.org/0.12.4/docs/Detailed-Topics/Tasks.html#mapr
[3] http://www.scala-sbt.org/0.13.0/api/index.html#sbt.Result


> Thanks!
> --
> Brice Figureau
> My Blog: http://www.masterzen.fr/
>
Reply all
Reply to author
Forward
0 new messages