2
votes

There is a job parametrized with Active Choices Parameters using Active Choices Plugin

Active Choices Parameters for a job

I want to trigger this job from the upstream job.
The upstream job should use the default parameters of the downstream job.

The parameter UtilityPath depends on UtilityVersion to evaluate itself and to form the list of choices.

How can I

  1. Get the list of choices returned by the groovy script of UtilityVersion from the upstream job?
  2. Supply my choice for UtilityVersion to the parameter UtilityPath, so it could generate it's own list of choices for me (again, on the upstream job).
  3. Trigger the job with my choices for parameters UtilityVersion and UtilityPath?
2
Am I right, that the upper part screenshot shows the parameter of the upstream job and the bottom part of the downstream job? - CSchulz
@CSchulz No, these are 2 parameters of the same downstream job. The upstream job has no parameters at all. - Egor Okhterov
But you want to show choices from the downstream job in the upstream job? - CSchulz
@CSchulz I need the upstream job to get the list of choices from the downstream job. The upstream job makes the decision on the value of UtilityVersion and UtilityPath (which will be used by the downstream build) based on the list of choices returned from the downstream job. - Egor Okhterov
And it is not possible to move it from the downstraem job to the upstream job and pass the values to the downstream job? - CSchulz

2 Answers

0
votes

Whatever your downstream job's parameter has (in the groovy script/ code section), if you can put that in a SCRIPTLER script (see Jenkins Scriptler plugin) then you can call that scriptler script and pass the same parameters (that you were passing in the downstream job) in your upstream job's BUILD section (either execute shell or Run Groovy script) as you mentioned, you don't want to add the same downstream parameters in your upstream job due to complexities). NOTE: See conditional run plugin on how to call Scriptler script (in Build section) if you don't want to call the Scriptler script if you are dealing with TFS vs ProjectC vs someAutomationD or when parameterX is set to true (your call there).

It's pretty much same what CSchulz mentioned but Scriptler script is better as you change the code/script in one place (Scriptler Script section - left hand side section on Jenkins home page) and then use/reuse that script anywhere (i.e. either in parameters which support Groovy Scriptler script --or-- in the build section) without requiring to read a downstream job's parameter values (some hacky way before even the downstream is called, time changes everything sometimes) --OR doing something crazy with Jenkins API to make it more complex.

0
votes

As I have tried, you cannot trigger upstream/downstream jobs with "Active Choice Plugin". Active choice and Reactive parameters get fired only if you trigger the job manually. For instance, if you tried to trigger the build from a bitbucket, active choice parameter get the value but reactive value will be shown as empty.

But you can achieve this in different ways. If you are triggering the first job manually (by yourself), set the downstram job parameters as string so you can read those values directly. Second option is to use environmental variable. Active choice is more over a conditional choice parameter. you can write groovy script to set parameters as environmental variable.This can be achieved with EnvInject Plugin. Write your conditional script in groovy and parameters are available in each and every build steps.

Groovy Script as an environment variable

Access environment variables in shell

use environment variables to pass parameters to downstream job Passing parameters