Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass env variable to Gradle test via command line?

Tags:

java

gradle

I have a standard java project layout and in some of my tests i have System.getenv("my_var"). I'd like to do run my tests using command line (from CI server) and pass the value of env var. Something like

./gradlew test -Dmy_var=xyz

but of course, this one doesn't work as tests are run by different jvm. so what's the exact command to pass the env var? i would prefer not to change my build scripts, create new tasks etc. i just want to pass env var via commandline. how can i do it?

like image 502
piotrek Avatar asked Oct 24 '25 16:10

piotrek


1 Answers

found it. as simple as:

my_var=xyz ./gradlew test 
like image 108
piotrek Avatar answered Oct 27 '25 05:10

piotrek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!