Hi All,
I have passed environment variables in my simulation.
I have succeeded in passing them using
Through shell file:
: ${Users:=1}
export Users=$Users
: ${Ramp:=1}
export Ramp=$Ramp
And accessing them in config file:
var totalUsers:Int = if (System.getenv(“Users”) != null) System.getenv(“Users”).toInt else 1
var rampOverSeconds:Int = if (System.getenv(“Ramp”) != null) System.getenv(“Ramp”).toInt else 1
Now I want to pass scenario names using config parameters.
val foo = exec(bar.foobar_function)
Can anyone help me understanding, how to pass and access config parameters for above scenario.
Thanks
Scenario names are not passed through the environment. For that, you need a command line parameter if you are using gatling.sh or gatling.bat. See http://gatling.io/docs/2.1.4/general/configuration.html#command-line-options
If you are using maven or sbt, someone else will have to tell you how to do that.
If you are using maven or sbt, someone else will have to tell you how to do that
I’d be interested to know if we can pass parameters through sbt. I was thinking, it’d just be:
$ SBT_OPTS=“-Dfoo=bar” sbt
// Script
println("value: " + System.getProperty(“foo”))
But I am getting null.
Many Thanks
Adrian
Even if Gatling SBT Plugin provides System properties propagation to Gatling itself, this won’t work as-is if you override javaOptions (which you do in your load tests published on Github).
To re-enable system properties propagation to Gatling :
`
import io.gatling.sbt.PropertyUtils._
javaOptions in Gatling := /* your javaOptions */ ++ propagatedSystemProperties
`
Cheers,
Pierre
Hi Pierre
import io.gatling.sbt.PropertyUtils._
I am receiving the error:
error: object PropertyUtils is not a member of package io.gatling.sbt
Woops….
import io.gatling.sbt.utils.PropertyUtils._
Hi Pierre,
Thanks for getting back.
Here is my set up:
// build.sbt
import io.gatling.sbt.utils.PropertyUtils._
javaOptions in Gatling := Seq("-Xms2G", “-Xmx5G”) ++ propagatedSystemProperties
// Gatling Script
println("value: " + System.getProperty(“foo”))
// JAVA_OPTS passed to sbt
JAVA_OPTS="-Dfoo=bar" sbt
However, when I run the test, I still the value as null.
Many Thanks
Adrian
Are you sure that JAVA_OPTS is used by SBT ?
For example, if you’re using Paul Philips’s script from sbt-extras, the env variable is JVM_OPTS, not JAVA_OPTS.
To be sure, try using your system property inside your build.sbt.
For example, add name := sys.props("foo”) to your build. And then run show name inside SBT.
If you get a null, this means that SBT itself doesn’t have access to your system property and so there’s not a single chance it can propagate it to Gatling.
Double check SBT help (sbt -h) to get sure that you’re using the correct environment variable to pass your system properties.
Cheers,
Pierre
Hi Pierre,
Thanks for the pointers. SBT_OPTS seem to work:
$ SBT_OPTS="-Denv=test" sbt
// script
val env = System.getProperty(“env”)
Many Thanks
Aidy
Hi All,
Sorry for breaking in the discussion.
I am not using sbt or maven.
I have configured a shell file which passes config parameters through environment variables, and I am successful passing them as per mentioned in first post.
Now I want to pass scenario names through environment variables, which i am not able to pass using string parameters.
Can you help me with any way which can be used for passing scenario names.
Thanks
I am trying to pass parameters from shell file.
: ${SingleFilter:=“Foo.getBarScenario”}
And fetch them in my simulation file.
val config_filter:String = if (System.getenv(“SingleFilter”) != null) System.getenv(“SingleFilter”) else “Foo1.getBar1”
// if I print value of config_filter here, it displays Foo.getBarScenario
val singleFiltrScns = exec(s"config_filter")
val fooUIScenario = scenario(“Foo UI Simulation”)
.exec(loginScns)
.exec(singleFiltrScns)
//but when I execute simulation gatling gives me following error
// 17:04:16.567 [ERROR] i.g.c.a.b.SessionHookBuilder$$anonfun$build$1$$anon$1 - ‘sessionHook-1’ failed to execute
You can’t set the scenario name via an environment variable. You use a command line parameter. Read the docs on startup parameters, and then build an appropriate shell script wrapper.