I am using gradlew within a container for a CI build.
ENV values are not being recognized when I add them in the bash shell.
Is there a way of passing the envs into the gradle build parameter or should the above be sufficient?
I'm not really sure about the problem here, is that you cannot read the variables inside gradle?
This question might help: In Gradle, is there a better way to get Environment Variables?
version = System.getenv("JENKINS_BUILD_NUMBER") ?: "0.1-SNAPSHOT"
is working fine in my build.gradle
scripts.
Here there is an example:
Well, that should definitely work fine.
that's my build.gradle
:
apply plugin: 'java'
apply plugin: 'groovy'
task('hello') {
println System.getenv("HI")
}
So, if I run:
export HI="hello there"
gradle hello
I get this:
hello there
:hello UP-TO-DATE
BUILD SUCCESSFUL
Total time: 0.869 secs
This works. Just make sure that the ENV variables are correctly defined in your CI conf.