Search code examples
scalamavengatling

How to set environment variables when executing a scenario with maven?


I have a gatling project where I make use of environment variables:

val Feeder: String = scala.util.Properties.envOrElse("FEEDER", "sts")

When I run it using maven I try to set the value of that variable, but I always get the default value:

$ mvn gatling:test -Dgatling.simulationClass=simulations.MySimulation -DFEEDER=something

I've also tried to just set the value in the terminal before executing maven:

$ FEEDER=something

$ mvn gatling:test -Dgatling.simulationClass=simulations.MySimulation

but I always get the default value "sts"

Am I missing something? How can I set the value I want to get?


Solution

  • You're confusing env variables and Java System Properties.

    scala.util.Properties.envOrElse is for the former while -DFEEDER=something is for the latter.

    Please use scala.util.Properties.propOrElse or sys.props.getOrElse.