Pankaj Verma
Pankaj Verma

Reputation: 51

seed job does not passes environment variable to groovy dsl script

I am using job-dsl-plugin. In my seed job 'a' I am setting a build environment variable using 'Inject environment variables to the build process' option and providing an environment variable as follows in 'Properties Content' :

SERVERADDRESS=abc

Now, the same seed job is also processing job DSLs as follows in 'Build' section as follows:

Look on Filesystem = enabled
DSL Scripts = **/*.groovy
Action for removed jobs = Ignore
Action for removed Views = Ignore

now, the above included groovy scripts is creating another job 'b' in which I am trying to access the 'SERVERADDRESS' variable value as follows:

goals('-DserverAddress=${SERVERADDRESS}')

but the above variable I cannot access in my groovy script. I can access standard environment variable for e.g. JOB_NAME, BUILD_ID, BUILD_TAG etc. in job 'b' but the custom variable (SERVERADDRESS) which I defined in job 'a' is not accessible.

Is there any way by which we can access custom defined variables in seed jobs to child jobs created by seed job?

Upvotes: 0

Views: 1368

Answers (1)

matijasx
matijasx

Reputation: 107

If you are using envInject just for setting custom parameters (instead of injecting file with parameters), use 'This project is parameterized' option in your seed job and set the parameters there.

You can get those variables with binding.variables.get('<your variable name>')

Upvotes: 2

Related Questions