I'm declaring 2 parameters in properties section of a Jenkins pipeline:
- a data center (can have multiple environment types)
- an environment type
The data center is of type ChoiceParameter; the list is retrieved from a database; when the data center changes in the drop-down list, the environment types should populate accordingly, also from the database, through a ScriptlerScript.
The problem is that when changing selection on data center, nothing happens for environment types list, which is a CascadeChoiceParameter with referencedParameters: 'DataCenter'.
How should I link the referenced parameter to the scriptlet script I'm using - what do I have to send ?
The issue is with [name:'DataCenter', value: '$DataCenter'] for second parameter - the value is not sent to the ScriptletScript when first drop-down value changes.
If I define the 2 parameters from the Jenkins interface - so not through the DSL pipeline - under Configure section, everything works as expected.
It's not working for me to use something other than properties section - I've tried using activeChoiceParameter inside pipeline section, but I get an error 'Build parameters definitions cannot have blocks @ line (...)', which is a known issue (see first example link below).
Examples I've used:
Jenkinsfile Active Choice Parameter
Active Choices Reactive Reference Parameter in jenkins pipeline
properties([
parameters([
[
$class: 'ChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
name: 'DataCenter',
script: [
$class: 'ScriptlerScript',
scriptlerScriptId:'getdatacenters.groovy',
parameters: [
[name:'StatusId', value:'']
]
]
],
[
$class: 'CascadeChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
name: 'EnvironmentType',
script: [
$class: 'ScriptlerScript',
scriptlerScriptId:'getenvtypesbydatacenter.groovy',
referencedParameters: 'DataCenter',
parameters: [
[name:'DataCenter', value: '$DataCenter']
]
]
]
])
])
pipeline {
...
Expected result: Second drop-down list populates when data center changes
Actual result: Nothing happens when data center changes
Pipeline with params configured in UI - behaves ok (environment types loading on data center change):