Skip to content

Instantly share code, notes, and snippets.

@LenarBad
Last active May 18, 2018 14:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LenarBad/a583cd3bf05129b4ad9df0e37a21c5cb to your computer and use it in GitHub Desktop.
Save LenarBad/a583cd3bf05129b4ad9df0e37a21c5cb to your computer and use it in GitHub Desktop.
Jenkins dynamic Extended Choice Parameter with service call (Groovy Script)
// host will be passed in the groovy bindings for extended choice plugin.
def getVersion = { host, path ->
try {
def version = new groovy.json.JsonSlurper().parse(new URL("https://${host}${path}")).version
return version
} catch(Exception e) {
return null
}
}
String version = getVersion(host, "/version")
if(version == null) {
version = getVersion(host, "/info")
}
return version ?: 'RELEASE'
def version = new groovy.json.JsonSlurper().parse(new URL("https://test.xxxx.com/info")).version
return [version]
// also set Default value if this failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment