Skip to content

Instantly share code, notes, and snippets.

@silabeer
Last active December 26, 2023 14:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save silabeer/2bb3baf37c7ee1dbed369e84d4b8d9d0 to your computer and use it in GitHub Desktop.
Save silabeer/2bb3baf37c7ee1dbed369e84d4b8d9d0 to your computer and use it in GitHub Desktop.
Jenkinsfile with Active Choice
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