Jenkins groovy execute trigger step another job in groovy script removes job source parameters

I am using a groovy script to run other tasks that are based on an example from the Groovy plugin page.

I get a list of tasks as a parameter, check their existence and run them with several parameters. See Main Launch Code:

// Prepare parameters array def params = [ new StringParameterValue('PARAM1', 'val1'), new StringParameterValue('PARAM2', 'val2'), ] def future = job.scheduleBuild2(0, new Cause.UpstreamCause(build), new ParametersAction(params)) println "Waiting for the completion of " + jobLink anotherBuild = future.get() 

My running jobs work fine, but with one major problem. Their initial parameters are lost and replaced with the new PARAM1 and PARAM2 .

How can I run a task and add to its default parameters and not replace them?

I tried to find a solution for him and did not find ...

EDIT: I thought not to set the parameters (and let the job use its default values), but set the environment variables to complete the job. Does anyone have an idea or example on how to do this?

+8
jenkins groovy
source share
2 answers

After several attempts, I decided to load the default parameters for the task that I am going to run, and add them to the parameter array that I am preparing, as in the example below.

I used the example here to get the initial default configuration.

I still need to add logic to the selection options and null values, but I am pleased with the current result.

Hope this helps.

+4
source share

These days, I would use something like a Build Flow plugin . This orchestral DSL / API reduces this code to:

  build('job', PARAM1: 'val1' PARAM2: 'val2') 

You can pass parameters as a hash map, those that are missing will revert to the default values.

One problem with this plugin: it may be abandoned soon. New alternative (not yet released): https://github.com/jenkinsci/workflow-plugin .

+4
source share

All Articles