0

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?

ecl0
  • 385
  • 1
  • 3
  • 13

1 Answers1

1

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.

Community
  • 1
  • 1
Marc
  • 356
  • 1
  • 8
  • basically i'm trying to build a project within a container and the project contains envs that I used locally. I am using a gradle wrapper to replicate my local gradle environment but cannot replicate the envs within the container - for example ADMIN=password is unrecognised when I run the gradlew script within the container. – ecl0 May 11 '17 at 12:18