在我的Scala测试中,我通过读取了一个环境变量sys.props.getOrElse("cassandra.test.host", DEFAULT_CASSANDRA_TEST_HOST)。
sys.props.getOrElse("cassandra.test.host", DEFAULT_CASSANDRA_TEST_HOST)
测试通过詹金斯进行。
我添加了一个Build using sbt作为构建步骤。
Build using sbt
通过查看SO上的类似问题,我想到了这个解决方案-即将“操作”字段设置为:
'; set javaOptions += "-Dcassandra.test.host=XX.XXX.XXX.XXX"; test'
但它不起作用。Properties.envOrElse执行时未设置任何变量。
Properties.envOrElse
Jenkins控制台输出包含:
[...] [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] Runlastfor details. [info] Reapplying settings... [...]
[...] [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
for details. [info] Reapplying settings... [...]
如果您不使用新的JVM执行测试,则设置javaOptions不会执行任何操作。SBT摘录:
javaOptions
> help javaOptions Options passed to a new JVM when forking.
这解释了为什么javaOptions不进行分叉测试时不使用您的代码。
您基本上有两种解决方案:
fork in Test := true
sbt -Dcassandra.test.host=XX.XXX.XXX.XXX test