Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sbt for continuous integration: print stacktrace and exit on error

I'm using Sbt for continuous integration (Bamboo). I want to check all the environment variables are set or get a descriptive error message. I use the following approach:

def env(n: String) = Option(System.getenv(n)).getOrElse(throw new RuntimeException("Undefined required environment variable " + n))

val mySetting = env("REQUIRED_ENV_VAR") + "..."

Instead, I get

[error] java.lang.ExceptionInInitializerError
[error] Use 'last' for the full log.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? q

Two questions:

  1. How to get full stacktrace without need to use 'last' (simple can't do it on Bamboo)?
  2. How to tell sbt to exit if project loading failed instead of asking for retry etc?
like image 550
nau Avatar asked Oct 23 '12 09:10

nau


2 Answers

sbt will not enable interactive mode if input stream will be "closed" with (such a hacky) trick:

cat /dev/null | sbt taskname

or if you are not able to use pipes create a shell script like this:

#!/bin/sh
sbt "$@" < /dev/null
like image 81
Andrey Kuznetsov Avatar answered Sep 17 '22 16:09

Andrey Kuznetsov


In sbt v1.3.9 (and probably earlier) there is the --batch switch.

$ sbt --help
Usage: sbt [options]
  ...
  --batch             disable interactive mode
  ...
like image 41
Edward Samson Avatar answered Sep 19 '22 16:09

Edward Samson