Dynamic or Conditional display of Jenkins job's parameters - jenkins

I am trying to use following jenkins job to generate Active Choices user selectable params for a job.
my ask is to show/hide textbox when heartbeat_consumer checkbox is selected/unselected. I would also like to store the value of user input in heartbeat_consumer_parms, which can be accessed thru env.heartbeat_consumer_parms. I plan to use this value in downstream jobs.
pipeline {
agent any
stages {
stage('Parameters'){
steps {
script {
properties([
parameters([
text(
defaultValue: '''''',
name: 'application_servers',
description: 'Please provide semicolon delimited (;) application server list ',
),
[$class: 'CascadeChoiceParameter',
choiceType: 'PT_CHECKBOX',
description: 'Select Services',
name: 'application_services_list',
referencedParameters: 'application_servers',
script:
[$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script: "return['']"
],
script: [
classpath: [],
sandbox: false,
script: '''
if (application_servers.length() > 0){
return["heartbeat_consumer", "surgeon_cloud_login", "system_configuration"]
}
'''
]
]
]
])
])
if (application_services_list.contains('heartbeat_consumer')){
text(
defaultValue: '''''',
name: 'heartbeat_consumer_parms',
description: 'Please provide heartbeatconsumer job parms ',
)
}
}
}
}
}
}
with current implmentation I am not seeing that textbox heartbeat_consumer_parms is being displayed at all.

Pipeline script for your scenario:
properties([
parameters([
[$class: 'ChoiceParameter',
choiceType: 'PT_CHECKBOX',
description: 'Select the Application Service from the Dropdown List',
filterLength: 1,
filterable: false,
name: 'application_services_list',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
"return['Could not get the services list']"
],
script: [
classpath: [],
sandbox: false,
script:
"return['heartbeat_consumer', 'surgeon_cloud_login', 'system_configuration']"
]
]
],
[$class: 'DynamicReferenceParameter',
choiceType: 'ET_FORMATTED_HTML',
description: 'SAdd params',
name: 'heartbeat_consumer_parms',
omitValueField: 'true',
referencedParameters: 'application_services_list',
script:
[$class: 'GroovyScript',
script: 'return["Could not get Information"]',
script: [
script: '''
if (application_services_list.equals("heartbeat_consumer")){
inputBox="<input type ='text' id = 'myText' name='value' >"
return inputBox
}
'''
]
]
]
])
])
pipeline {
environment {
vari = ""
}
agent any
stages {
stage ("Example") {
steps {
script{
echo "${params.application_services_list}"
echo '\n'
echo "${params.heartbeat_consumer_parms}"
}
}
}
}
}
Please find the screenshot of the output:
Output of pipeline after build:

this worked for me,
pipeline {
agent any
stages {
stage('Parameters'){
steps {
script {
properties([
parameters([
text(
defaultValue: '''''',
name: 'application_servers',
description: 'Please provide semicolon delimited (;) application server list ',
),
[$class: 'CascadeChoiceParameter',
choiceType: 'PT_CHECKBOX',
description: 'Select Services',
name: 'application_services_list',
referencedParameters: 'application_servers',
script:
[$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script: "return['']"
],
script: [
classpath: [],
sandbox: false,
script: '''
if (application_servers.length() > 0){
return["heartbeat_consumer", "surgeon_cloud_login", "system_configuration"]
}
'''
]
]
],
[$class: 'DynamicReferenceParameter',
choiceType: 'ET_FORMATTED_HTML',
description: 'enter job params',
name: 'hb_job_params',
referencedParameters: 'application_services_list',
script:
[$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script: "return['']"
],
script: [
classpath: [],
sandbox: false,
script: '''
if (application_services_list.contains('heartbeat_consumer')){
return """<textarea name=\"value\" rows=\"5\" class=\"setting-input \"></textarea>"""
}
'''
]
],
omitValueField: true
],
])
])
}
}
}
}
}
I used, DynamicReferenceParameter for using HTML generated textarea however accessing entered textarea values was tricky. after a bit of researching I found that,
The trick for formatting a text input box is to format the HTML in a way that reflects the HTML Jenkins uses to display parameters in a job submission form. The easiest way to do this is to review the HTML Jenkins uses to display an existing String parameter.
src: https://github.com/biouno/uno-choice-plugin/wiki/Using-Uno-Choice-for-Dynamic-Input-Text-Box-Defaults

Related

How to order Jenkins Parameters using groovy script

I am using this groovy script to parameterize a Jenkins Job:
properties([
parameters([
[$class: 'ChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
description: 'Select param1',
filterLength: 1,
filterable: false,
name: 'param1',
randomName: 'choice-parameter-5631314439613978',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: true,
script:
'return[\'Could not get param1\']'
],
script: [
classpath: [],
sandbox: true,
script:
'return["value1", "value2", "value3"]'
]
]
],
[$class: 'CascadeChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
description: 'Select param3',
filterLength: 1,
filterable: false,
name: 'param3',
randomName: 'choice-parameter-10000000000000000',
referencedParameters: 'param1',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: true,
script:
'return[\'Could not get param3\']'
],
script: [
classpath: [],
sandbox: true,
script:
''' if (param1.equalsIgnoreCase('value1')){
return["1", "2"]
}
else if(param1.equalsIgnoreCase("value2")){
return["3", "4"]
}
else if(param1.equalsIgnoreCase("value3")){
return["5", "6"]
}
'''
]
]
]
])
])
pipeline {
agent any
parameters {
string(name: "param2", defaultValue: "test1", description: "Test value")
}
stages {
stage ("Example") {
steps {
script{
echo 'Hello'
}
}
}
}
}
If I use this script as is, On the Jenkins job, parameters will be shown in this order: param2, param1, param3. What I really want, is to have them in this order: param1, param2, param3.
From the code as you can see, for param 1 and 3 I am using Active Choice Parameter and Active Choice Reactive Parameter which will be dependent from the value selected in param1. For param2, I need it as string.
Is there a way to achieve this, have them in this order: param1, param2, param3?
Okay, i found that i can use also this in the properties:
[$class: 'StringParameterDefinition',
description: 'Enter param2',
name: 'param2',
defaultValue: '',
randomName: 'string-parameter-1343433232',
trim: true
]

jenkins - create dynamic textbox and passwords when checkbox or filed is used

i want to have checkbox/single select , when user checked the checkbox/use the filed in the single select , it will create dynamically few text box(5).2 of those text box should contain password/keys (so should be encrypted /not shown in jenkins parameters.
i tried with Active Choices Parameter and Active Choices Reactive Reference Parameter from jenkins file and from gui
example:
i have parameters :
Active Choices Parameter
name: use_custom
Groovy Script: return ["true", "false"]
Choice Type: single select
Active Choices Reactive Reference Parameter
name: custom_values
Groovy Script:
myPassword = ''
if ( use_custom == "true") {
return """
inputBox="<input class='setting-input' name='value' type='password' value=''>"
inputBox="<input class='setting-input' name='value' type='text' value=''>"
"""
echo(text1)
}
else {
return ""
}
Choice Type: formatted html ,
Referenced parameters: use_custom
i created 2 dynamic html box (work only for text box , not passwords/key that user need to enter manually (not via jenkins cred)
example output in parameters:
custom_values: 1234,11
*it show the password in jenkins params (free text)
what is the solution to allow user to write password and text box ( 2 pass, 3 box) when another field is true (password cannot be free text)
groovy pipeline example(in case of Env:dev , create 2 textbox):
properties([
parameters([
[$class: 'ChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
description: 'Select the Env Name from the Dropdown List',
filterLength: 1,
filterable: true,
name: 'Env',
randomName: 'choice-parameter-5631314439613978',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
'return[\'Could not get Env\']'
],
script: [
classpath: [],
sandbox: false,
script:
'return["Dev","QA","Stage","Prod"]'
]
]
],
// [$class: 'CascadeChoiceParameter',
// choiceType: 'ET_FORMATTED_HTML',
// description: 'Select the Server from the Dropdown List',
// filterLength: 1,
// filterable: true,
// name: 'Server',
// randomName: 'choice-parameter-5631314456178619',
// referencedParameters: 'Env',
[$class: 'DynamicReferenceParameter',
choiceType: 'ET_FORMATTED_HTML',
omitValueField: true,
description: '123',
name: 'Server',
randomName: 'choice-parameter-5631314456178624',
referencedParameters: 'Env',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
'return[\'Could not get Environment from Env Param\']'
],
script: [
classpath: [],
sandbox: false,
script:
''' if (Env.equals("Dev")){
inputBox2 = "<input name='value' class='setting-input' type='text'>"
inputBox = "password(name: 'KEY', description: 'Encryption key')"
return[inputBox]
}
else {
return ""
}
'''
]
]
],
[$class: 'DynamicReferenceParameter',
choiceType: 'ET_FORMATTED_HTML',
omitValueField: true,
description: '1234',
name: 'pass',
//randomName: 'choice-parameter-5631314456178624',
referencedParameters: 'Env',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
'return[\'Could not get Environment from Env Param\']'
],
script: [
classpath: [],
sandbox: false,
script:
''' if (Env.equals("Dev")){
inputBox = "<input name='value' class='setting-input' type='password'>"
return[inputBox]
}
else {
return ""
}
'''
]
]
]
])
])
pipeline {
environment {
vari = ""
}
agent any
stages {
stage ("Example") {
steps {
script{
echo 'Hello'
echo "${params.Env}"
echo "${params.Server}"
echo "${params.pass}"
if (params.Server.equals("Could not get Environment from Env Param")) {
echo "Must be the first build after Pipeline deployment. Aborting the build"
currentBuild.result = 'ABORTED'
return
}
echo "Crossed param validation"
} }
}
}
}
i tried also with mask_plugin , it mask from console output , not from parameters , any ideas ?
thanks

Cannot return the file value as list in jenkins active choice reference parameter script in jenkins

Hello I have the following code as my Jenkinsfile.
pipeline {
agent any
parameters{
string(name: 'IP_ADDRESS', defaultValue: '', description: 'Enter server IP address')
string(name: 'USERNAME', defaultValue: '', description: '')
string(name: 'PASSWORD', defaultValue: '', description: '')
}
environment{
VERSION='1.3.0'
}
stages {
stage('Build') {
steps {
echo 'Built'
sh(script:"python sshMac.py ${IP_ADDRESS} ${USERNAME} ${PASSWORD}", returnStatus: true, returnStdout: true)
}
}
stage('Test') {
steps {
script{
env.FILENAME = readFile 'macAdds.properties'
env.FILEDATA = FILENAME.tokenize( "," )
input message: 'Please choose one',
parameters: [
[$class: 'ChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
description: 'Select the Environemnt from the Dropdown List',
filterLength: 1,
filterable: false,
name: 'ENVIRONMENT',
script: [$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: true,
script: 'return ["ERROR"]'
],
script: [
classpath: [],
sandbox: true,
script: """
return['1', '2', '3', '4']
""".stripIndent()
]
]
],
[$class: 'ChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
description: 'Select the Environemnt from the Dropdown List',
filterLength: 1,
filterable: false,
name: 'ENVIRONMENT2',
script: [$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: true,
script: 'return ["ERROR"]'
],
script: [
classpath: [],
sandbox: true,
script: """
return['1', '2', '3', '4', '5']
""".stripIndent()
]
]
],
[$class: 'CascadeChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
description: 'Select a choice',
filterLength: 1,
filterable: false,
name: 'choice1',
referencedParameters: 'ENVIRONMENT',
script: [$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: true,
script: 'return ["ERROR"]'
],
script: [
classpath: [],
sandbox: true,
script: """
def tokens = ${FILENAME}.tokenize(',')
switch(ENVIRONMENT) {
case "1":
return ${env.FILEDATA}
case "2":
return ${env.FILEDATA}
case "3":
return ${env.FILEDATA}
case "4":
return ${env.FILEDATA}
}
"""
]
]
],
text(name: 'vertical', defaultValue: "${FILENAME}")
]
}
echo 'Testing'
echo "${FILENAME}"
echo "${FILEDATA}"
}
}
stage('Deploy') {
steps {
echo 'Deploying'
}
}
}
}
So Here I have obtained the values from a file (FILENAME) and split them into a list (FILEDATA). It works perfectly and it prints out and echo too. Actually it returns a set of Mac addresses from a macAdds.properties such as [ff:ff:ee:ee:ee:ff, ff:ee:dd:aa:bb:ee, ff:ee:aa:cc:bb:dd].
But in my active choice reference parameter (choice1) when I returns the FILEDATA value in my switch case as single select it does not work out where it will run fall back script and gives me an error. I have tested returning some random values given manually to the switch statements where it works perfectly. I want to know why I can't return the values in my active choice reference parameter (choice1) script. Help me out!! Thank you
Well I have figured out the answer for this solution. When you are using groovy sandbox value as through you can do many thing without limitations. But you have to approve the script manually from Manage Jenkins => Script Approval. Hope this will help out someone. Thanks!

Jenkins generate new parameters based on another parameter value

I have a choice parameter called 'Data Center' which has two values DC01 and DC02. If user chooses DC01 I want few other build parameters to show up, if he chooses DC02 I want other parameters to show up. Is there any way to do it?
If user chooses DC01, I want two more fields such as 'hostname' and 'IP address' which are just text fields.
I have tried using Active Choice Plugin, but I don't think we can generate text field parameters using that.
Can anyone help?
We can generate text field parameters using Active Choices Plugin.
We will use two types of parameters here: Active Choices Parameter and Active Choices Reactive Reference Parameter
Active Choices Reactive Reference Parameter
In Active Choices Reactive Reference Parameter, there are wide variety of rendering options available, of which one is Formatted HTML i.e. in the return string you can pass the html tags.
So, making use of the above two parameters, here is the pipeline code that will help in your case:
Note: After saving the below pipeline code, first Click on Build Now. After the build got success, then refresh the page. You will be able to see the option Build with Parameters. You can also see in the Job Configuration page, all the fields of This build is parameterized gets populated automatically once you build the job after saving the pipeline.
properties([
parameters([
[$class: 'ChoiceParameter',
choiceType: 'PT_CHECKBOX',
description: 'Select the Application Service from the Dropdown List',
filterLength: 1,
filterable: false,
name: 'data_center',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
"return['Could not get the services list']"
],
script: [
classpath: [],
sandbox: false,
script:
"return['DC01', 'DC02', 'DC03']"
]
]
],
[$class: 'DynamicReferenceParameter',
choiceType: 'ET_FORMATTED_HTML',
description: 'enter job params',
name: 'hostname',
referencedParameters: 'data_center',
script:
[$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script: "return['']"
],
script: [
classpath: [],
sandbox: false,
script: '''
if (data_center.contains('DC01')){
return """<textarea name=\"value\" rows=\"5\" class=\"setting-input \"></textarea>"""
} else
if (data_center.contains('DC02')){
return """<textarea name=\"value\" rows=\"5\" class=\"setting-input \"></textarea>"""
}
'''
]
],
omitValueField: true
],
[$class: 'DynamicReferenceParameter',
choiceType: 'ET_FORMATTED_HTML',
description: 'enter job params',
name: 'ipaddress',
referencedParameters: 'data_center',
script:
[$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script: "return['']"
],
script: [
classpath: [],
sandbox: false,
script: '''
if (data_center.contains('DC01')){
return """<textarea name=\"value\" rows=\"5\" class=\"setting-input \"></textarea>"""
} else
if (data_center.contains('DC02')){
return """<textarea name=\"value\" rows=\"5\" class=\"setting-input \"></textarea>"""
}
'''
]
],
omitValueField: true
],
[$class: 'DynamicReferenceParameter',
choiceType: 'ET_FORMATTED_HTML',
description: 'enter job params',
name: 'port_number',
referencedParameters: 'data_center',
script:
[$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script: "return['']"
],
script: [
classpath: [],
sandbox: false,
script: '''
if (data_center.contains('DC02')){
return """<textarea name=\"value\" rows=\"5\" class=\"setting-input \"></textarea>"""
}
'''
]
],
omitValueField: true
]
])
])
pipeline {
environment {
vari = ""
}
agent any
stages {
stage ("Example") {
steps {
script{
echo "${params.data_center}"
echo '\n'
echo "${params.hostname}"
echo "${params.ipaddress}"
echo "${params.port_number}"
}
}
}
}
}
Screenshots:
Output when data center DC01 is selected,
Output when data center DC02 is selected,

Active Choices Reactive Reference Parameter in jenkins pipeline

I'm using the Active Choices Reactive Reference Parameter plugin in a dsl job here the code
parameters {
activeChoiceParam('choice1') {
description('select your choice')
choiceType('RADIO')
groovyScript {
script("return['aaa','bbb']")
fallbackScript('return ["error"]')
}
}
activeChoiceReactiveParam('choice2') {
description('select your choice')
choiceType('RADIO')
groovyScript {
script("if(choice1.equals("aaa")){return ['a', 'b']} else {return ['aaaaaa','fffffff']}")
fallbackScript('return ["error"]')
}
referencedParameter('choice1')
}
and it work's fine what i want now is how to use the activeChoiceReactiveParam in a jenkinsFile for pipeline job i did that :
properties(
[
[
$class : 'ParametersDefinitionProperty',
parameterDefinitions: [
[
$class : 'ChoiceParameterDefinition',
choices : 'aaa\nbbb',
description: 'select your choice : ',
name : 'choice1'
]
but how can i add the choice2 parameter !!!
I was in need of the similar solution.
I did not find any related answers/examples specific to Active Choices plugin anywhere in my google search.
With some R & D, finally I was able to get this done for a pipeline project.
Here is the Jenkinsfile code
properties([
parameters([
[$class: 'ChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
description: 'Select the Env Name from the Dropdown List',
filterLength: 1,
filterable: true,
name: 'Env',
randomName: 'choice-parameter-5631314439613978',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
'return[\'Could not get Env\']'
],
script: [
classpath: [],
sandbox: false,
script:
'return["Dev","QA","Stage","Prod"]'
]
]
],
[$class: 'CascadeChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
description: 'Select the Server from the Dropdown List',
filterLength: 1,
filterable: true,
name: 'Server',
randomName: 'choice-parameter-5631314456178619',
referencedParameters: 'Env',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
'return[\'Could not get Environment from Env Param\']'
],
script: [
classpath: [],
sandbox: false,
script:
''' if (Env.equals("Dev")){
return["devaaa001","devaaa002","devbbb001","devbbb002","devccc001","devccc002"]
}
else if(Env.equals("QA")){
return["qaaaa001","qabbb002","qaccc003"]
}
else if(Env.equals("Stage")){
return["staaa001","stbbb002","stccc003"]
}
else if(Env.equals("Prod")){
return["praaa001","prbbb002","prccc003"]
}
'''
]
]
]
])
])
pipeline {
environment {
vari = ""
}
agent any
stages {
stage ("Example") {
steps {
script{
echo 'Hello'
echo "${params.Env}"
echo "${params.Server}"
if (params.Server.equals("Could not get Environment from Env Param")) {
echo "Must be the first build after Pipeline deployment. Aborting the build"
currentBuild.result = 'ABORTED'
return
}
echo "Crossed param validation"
} }
}
}
}
Even you can use "Active Choices Reactive Reference Parameter" with below definitions and rest of the code, follow as in above example.
[$class: 'DynamicReferenceParameter',
choiceType: 'ET_FORMATTED_HTML',
description: 'These are the details in HTML format',
name: 'DetailsInHTML',
omitValueField: false,
randomName: 'choice-parameter-5633384460832175',
referencedParameters: 'Env, Server',
script: [
$class: 'ScriptlerScript',
parameters: [[$class: 'org.biouno.unochoice.model.ScriptlerScriptParameter', name: '', value: '$value']],
scriptlerScriptId: 'script.groovy'
]
]
Note: Ensure you have "," delimiter between multiple parameter definition blocks.
Hope this helps someone.
Instead of using the Active Choices Reactive Reference Parameter i did below and it's working fine !!!
node('slave') {
def choice1
def choice2
stage ('Select'){
choice1 = input( id: 'userInput', message: 'Select your choice', parameters: [ [\$class: 'ChoiceParameterDefinition', choices: 'aa\nbb', description: '', name: ''] ])
if(choice1.equals("aa")){
choice2 = input( id: 'userInput', message: 'Select your choice', parameters: [ [\$class: 'ChoiceParameterDefinition', choices: 'yy\nww', description: '', name: ''] ])
}else{
choice2 = input( id: 'userInput', message: 'Select your choice', parameters: [ [\$class: 'ChoiceParameterDefinition', choices: 'gg\nkk', description: '', name: ''] ])
}
}
}
Thanks a ton #Yogeesh. It helped a lot.
In my case, the requirement was to select multiple instead of one. So, used choiceType: 'PT_CHECKBOX', and it served the purpose.
properties([
parameters([
[$class: 'ChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
description: 'Select the Env Name from the Dropdown List',
filterLength: 1,
filterable: true,
name: 'Env',
randomName: 'choice-parameter-5631314439613978',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
'return[\'Could not get Env\']'
],
script: [
classpath: [],
sandbox: false,
script:
'return["Dev","QA","Stage","Prod"]'
]
]
],
[$class: 'CascadeChoiceParameter',
choiceType: 'PT_CHECKBOX',
description: 'Select Servers',
filterLength: 1,
filterable: true,
name: 'Server',
randomName: 'choice-parameter-5631314456178619',
referencedParameters: 'Env',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
'return[\'Could not get Environment from Env Param\']'
],
script: [
classpath: [],
sandbox: false,
script:
''' if (Env.equals("Dev")){
return["devaaa001","devaaa002","devbbb001","devbbb002","devccc001","devccc002"]
}
else if(Env.equals("QA")){
return["qaaaa001","qabbb002","qaccc003"]
}
else if(Env.equals("Stage")){
return["staaa001","stbbb002","stccc003"]
}
else if(Env.equals("Prod")){
return["praaa001","prbbb002","prccc003"]
}
'''
]
]
]
])
I made the initial sample work for me.
I had to change ' for " in the return statement return ["a", "b"] and " by ' in the script statement script(' ')
job("MyJob") {
description ("This job creates ....")
//def targetEnvironment=""
parameters {
activeChoiceParam('choice1') {
description('select your choice')
choiceType('RADIO')
groovyScript {
script('return["aaa","bbb"]')
fallbackScript('return ["error"]')
}
}
activeChoiceReactiveParam('choice2') {
description('select your choice')
choiceType('RADIO')
groovyScript {
script(' if(choice1.equals("aaa")) { return ["a", "b"] } else {return ["aaaaaa","fffffff"] } ')
fallbackScript('return ["error"]')
}
referencedParameter('choice1')
}
}
}
Is there any way that we can put the script logic in a function and call
for example:
[$class: 'CascadeChoiceParameter',
choiceType: 'PT_CHECKBOX',
description: 'Select Servers',
filterLength: 1,
filterable: true,
name: 'Server',
randomName: 'choice-parameter-5631314456178619',
referencedParameters: 'Env',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
'return[\'Could not get Environment from Env Param\']'
],
script: [
classpath: [],
sandbox: false,
script:
''' if (Env.equals("Dev")){
return["devaaa001","devaaa002","devbbb001","devbbb002","devccc001","devccc002"]
}
else if(Env.equals("QA")){
return["qaaaa001","qabbb002","qaccc003"]
}
else if(Env.equals("Stage")){
return["staaa001","stbbb002","stccc003"]
}
else if(Env.equals("Prod")){
return["praaa001","prbbb002","prccc003"]
}
'''
]
]
]```
define below code in funciton and call ?
if (Env.equals("Dev")){
return["devaaa001","devaaa002","devbbb001","devbbb002","devccc001","devccc002"]
}
else if(Env.equals("QA")){ return["qaaaa001","qabbb002","qaccc003"] } else if(Env.equals("Stage")){ return["staaa001","stbbb002","stccc003"] } else if(Env.equals("Prod")){ return["praaa001","prbbb002","prccc003"]
}
Try something like that:
properties(
[
[
$class : 'ParametersDefinitionProperty',
parameterDefinitions: [
[
$class : 'ChoiceParameterDefinition',
choices : 'aaa\nbbb',
description: 'select your choice : ',
name : 'choice1'
],
[
$class : 'ChoiceParameterDefinition',
choices : 'ccc\nddd',
description: 'select another choice : ',
name : 'choice2'
]

Resources