0
votes

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?

1
If you only have a few variables you could make the downstream jobs parameterized jobs and pass the environment variables in the parent job as a parameter to the child job.Tuffwer
The child jobs that seed job creates are actually not downstream jobs of the seed job. It's just that seed job is further creating another two jobs using groovy script.Pankaj Verma

1 Answers

2
votes

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>')