Michael S.
Michael S.

Reputation: 701

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?

Upvotes: 8

Views: 8766

Answers (2)

Ibrahim.H
Ibrahim.H

Reputation: 1195

A shorter groovy way would be like this:

def envVar = System.env['my_env_var']

Here is an example.

Upvotes: 2

Peter
Peter

Reputation: 5164

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

Example:


def envVar = System.getenv('my_env_var')

Upvotes: 8

Related Questions