patternMinor
Groovy script to show only selected item
Viewed 0 times
scriptshowitemselectedonlygroovy
Problem
I used jenkins Active choices plugin and Mavenmetadata plugin to build above UI. When I click a radio button particular version only should be display. How can I write a groovy script to fulfill above requirement?
Below images showing my groovy scripts.
Below images showing my groovy scripts.
Solution
You can use the Jenkins pipeline syntax to get the groovy script. For example below code will generate radio buttons for active choice parameter. you can generate scripts like this from your jenkins instance at http://localhost:8080/pipeline-syntax/. More info is here https://jenkins.io/doc/book/pipeline/getting-started/#snippet-generator
def createInputParameters(){
([[$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false],
parameters([[$class: 'ChoiceParameter', choiceType: 'PT_RADIO', description: '',
filterLength: 1, filterable: false, name: 'Select_snapshot_or_release',
randomName: 'choice-parameter-1683871426502398',
script: [$class: 'GroovyScript', fallbackScript: [classpath: [], sandbox: true,
script: 'return "Error"'],
script: [classpath: [], sandbox: true,
script: '''return[
\'snapshots\',\'release\']''']]]]),
[$class: 'ThrottleJobProperty', categories: [],
limitOneJobWithMatchingParams: false, maxConcurrentPerNode: 0,
maxConcurrentTotal: 0,
paramsToUseForLimit: '', throttleEnabled: false, throttleOption:
'project']])
}Code Snippets
def createInputParameters(){
([[$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false],
parameters([[$class: 'ChoiceParameter', choiceType: 'PT_RADIO', description: '',
filterLength: 1, filterable: false, name: 'Select_snapshot_or_release',
randomName: 'choice-parameter-1683871426502398',
script: [$class: 'GroovyScript', fallbackScript: [classpath: [], sandbox: true,
script: 'return "Error"'],
script: [classpath: [], sandbox: true,
script: '''return[
\'snapshots\',\'release\']''']]]]),
[$class: 'ThrottleJobProperty', categories: [],
limitOneJobWithMatchingParams: false, maxConcurrentPerNode: 0,
maxConcurrentTotal: 0,
paramsToUseForLimit: '', throttleEnabled: false, throttleOption:
'project']])
}Context
StackExchange DevOps Q#5482, answer score: 1
Revisions (0)
No revisions yet.