Last active
December 26, 2023 14:02
-
-
Save silabeer/2bb3baf37c7ee1dbed369e84d4b8d9d0 to your computer and use it in GitHub Desktop.
Jenkinsfile with Active Choice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
properties([ | |
parameters([ | |
[$class: 'ChoiceParameter', | |
choiceType: 'PT_SINGLE_SELECT', | |
description: 'Select a choice', | |
filterLength: 1, | |
filterable: false, | |
name: 'component', | |
script: [$class: 'GroovyScript', | |
fallbackScript: [classpath: [], sandbox: false, script: 'return ["Could not get component"]'], | |
script: [classpath: [], sandbox: false, | |
script: """ | |
import groovy.json.JsonSlurperClassic | |
def list = [] | |
def connection = new URL("https://run.mocky.io/v3/e406ee99-be79-4d50-818f-b186dad7f4f4") | |
.openConnection() as HttpURLConnection | |
connection.setRequestProperty('Accept', 'application/json') | |
def json = connection.inputStream.text | |
data = new JsonSlurperClassic().parseText(json) | |
data.each { component -> | |
list += component.name | |
} | |
return list | |
""" | |
]]], | |
, | |
[$class: 'CascadeChoiceParameter', | |
choiceType: 'PT_SINGLE_SELECT', | |
description: 'Select Version', | |
filterLength: 1, | |
filterable: true, | |
name: 'version', | |
referencedParameters: 'component', | |
script: [ | |
$class: 'GroovyScript', | |
fallbackScript: [ | |
classpath: [], | |
sandbox: false, | |
script: | |
'return[\'Could not get version\']' | |
], | |
script: [ | |
classpath: [], | |
sandbox: false, | |
script: | |
""" | |
import groovy.json.JsonSlurperClassic | |
def list = [] | |
def connection = new URL("https://run.mocky.io/v3/c782ae33-98a2-4994-acc4-14c0b5cc7655") | |
.openConnection() as HttpURLConnection | |
connection.setRequestProperty('Accept', 'application/json') | |
def json = connection.inputStream.text | |
data = new JsonSlurperClassic().parseText(json) | |
data.data.each { it -> | |
if (it.component == component ) { | |
list += it.version | |
} | |
} | |
return list | |
""" | |
] | |
] | |
] | |
]) | |
]) | |
pipeline { | |
agent any | |
stages { | |
stage("Component Name") { | |
steps { | |
sh "echo Selected component ${params.component}" | |
} | |
} | |
stage("Version") { | |
steps { | |
sh "echo Selected version ${params.version}" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment