Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing environment variables from Groovy scripts

I have to access an environment variable from my Groovy script. I am not using Jenkins. How do I get the variable?

like image 312
Michael S. Avatar asked Jun 20 '26 06:06

Michael S.


2 Answers

Use java.lang.System#getenv(java.lang.String)

Example:


def envVar = System.getenv('my_env_var')
like image 148
Peter Avatar answered Jun 22 '26 13:06

Peter


A shorter groovy way would be like this:

def envVar = System.env['my_env_var']

Here is an example.

like image 37
Ibrahim.H Avatar answered Jun 22 '26 13:06

Ibrahim.H