-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to make env vars available to JVMs? #189
Comments
Hi @autonomousapps, I have shared this with our engineering team. |
Hi! I apologize that nobody has gotten back to you yet. Are you still having issues with this? Once an environment variable is exposed via envman it should be accessible just like any other environment variable... |
Still having issues, although honestly I haven't tried for weeks. It has completely blocked progress on this new step, which I had hoped to share to the wider community. The last thing I tried before giving up was printing all of the env vars from my groovy script. In pseudocode, I ran System.getenv().forEach {
println "$key -> $value"
} and when I looked at the logs, I actually saw DOZENS of nearly blank lines. The only thing on those lines was an |
I haven't actually dug into your code to see what's going on, but I suspect this has to do with the fact that environment variables on Bitrise are scoped. Sometimes they are scoped to their workflow, sometimes they are scoped to a specific step. Parent processes can’t access environment variables exposed by child processes. Please take a look at the documentation here: |
Also, you may want to take a look at this thread: Envman doesn't load the values in the same step, only in subsequent steps. |
Conceptually, my step is very simple:
So if anything the groovy script is the child process and should inherit from its parent(s), which I assume are (1) the bitrise workflow, (2) bitrise step, and (3) shell that launched the script, in that order. It's been a while since I tried to do anything with this, so I can't now recall if the shell which launched the groovy script had access to the env vars. |
When you get a chance, please check that the shell launching the groovy script has access to the environment variables. |
Honestly not sure what to do anymore. I can see the env var in my bash script, which invokes groovy. In my groovy script, it always comes up blank. Yet, if I do System.getenv().each { println it } it will print all the env vars. But trying to do def env = System.getenv()
println env['SOME_VAR'] // prints nothing I have also tried System.getenv().each {
println it
println " class name = ${it.class.simpleName}"
} and the second line is always blank. This should be impossible. Groovy is a JVM language and everything has a type. I have tried running this same groovy script locally, not via a bitrise step, and everything works as expected. I have also tried invoking my groovy script from a bash script, and everything works as expected. Something about the context of running inside bitrise has irrevocably (apparently) broken Groovy. Shot in the dark: could this be a character encoding issue? How could I check that? |
Quick follow-up: I wrote a gradle task -- in groov -- and executed it using the gradle script runner step. It works perfectly. tasks.register("royalPenguin") {
doLast {
def path = System.getenv('BITRISE_APK_PATH')
println "BITRISE_APK_PATH=$path"
}
} not sure why this works but the "raw" groovy script doesn't. |
I am working on a new step that would let people execute arbitrary Groovy scripts (https://github.com/hiyainc/bitrise-step-groovy-script-runner). During testing in my own pipeline, though, I am unable to access environment variables I expect to be present. I use the standard JVM approach of calling
System.getenv('BITRISE_BUILD_NUMBER')
(for example). When I test that in a bash script (with$BITRISE_BUILD_NUMBER
), I get the expected value. When I test it in my Groovy script, it's always a blank string (not even null). I have tested this same Groovy script locally, andSystem.getenv(...)
works as expected.How does envman -- and indeed, Bitrise -- expose environment variables to steps?
To provide further examples, I have a step that has this output:
and I cannot access that env var in my groovy step which runs immediately afterwards. Just for the hell of it, I inserted a bash step between the two that does this:
and I also could not access
PROD_RELEASE_APK_PATH
. This works when consumed from a bash script.Thanks for your time.
The text was updated successfully, but these errors were encountered: