nau
nau

Reputation: 1165

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?

Upvotes: 8

Views: 1159

Answers (2)

Edward Samson
Edward Samson

Reputation: 2425

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

$ sbt --help
Usage: sbt [options]
  ...
  --batch             disable interactive mode
  ...

Upvotes: 1

Andrey Kuznetsov
Andrey Kuznetsov

Reputation: 11840

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

Upvotes: 8

Related Questions