In my scala test, I read an environemnt variable via sys.props.getOrElse("cassandra.test.host", DEFAULT_CASSANDRA_TEST_HOST)
.
The tests are run via Jenkins.
I have added a Build using sbt
as a build step.
By looking at similar questions on SO, I came up with this solution - i.e. setting the Actions field to:
'; set javaOptions += "-Dcassandra.test.host=XX.XXX.XXX.XXX"; test'
But it doesnt work. No variable is set when Properties.envOrElse
is executed.
The Jenkins console output contains:
[...]
[util-sessionizer] $ java -jar /usr/local/bin/sbt-launch.jar '; set javaOptions += "-Dcassandra.test.host=XX.XXX.XXX.XXX"; test'
[info] Loading project definition from /jenkins/workspace/util-sessionizer/project/project
[info] Loading project definition from /jenkins/workspace/util-sessionizer/project
[info] Set current project to util-sessionizer (in build file:/jenkins/workspace/util-sessionizer/)
[info] Defining *:javaOptions
[info] The new value will be used by *:runner, compile:run::runner and 4 others.
[info] Run `last` for details.
[info] Reapplying settings...
[...]
If you're not forking a new JVM to execute your tests, setting javaOptions
does nothing.
Excerpt from SBT itself:
> help javaOptions
Options 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:
fork in Test := true
to run your tests in forked JVMsOr pass your system properties to SBT itself :
sbt -Dcassandra.test.host=XX.XXX.XXX.XXX test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With