How to pass environment variables to a sbt test build step in Jenkins?
If you're not forking a new JVM to execute your tests, setting javaOptions
does nothing.Excerpt from SBT itself:
> help javaOptionsOptions passed to a new JVM when forking.
This explains why your javaOptions
are not used when you're not forking your tests.
You have basically two solutions:
- Either set
fork in Test := true
to run your tests in forked JVMs Or pass your system properties to SBT itself :
sbt -Dcassandra.test.host=XX.XXX.XXX.XXX test
You're setting a system property with -Dcassandra.test.host=XX.XXX.XXX.XXX"
, but then using Properties.envOrElse
which is for environment variables. See Environment Variables.
Try this:
sys.props.getOrElse("cassandra.test.host", DEFAULT_CASSANDRA_TEST_HOST)
It seems that adding fork in Test := true
solves the problem - even if, to be honest, I did not investigated the extact corrlation between the two events (i.e. adding fork in Test := true
and having the system property passed to my tests.
So the correct argument to be passed to sbt is:
'; set fork in Test := true; set javaOptions += "-Dcassandra.test.host=XX.XXX.XXX.XXX"; test'