Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lukenvn/72e1cdcfd9274f24dccb2ba17bc59c01 to your computer and use it in GitHub Desktop.
Save lukenvn/72e1cdcfd9274f24dccb2ba17bc59c01 to your computer and use it in GitHub Desktop.
Jenkins pipeline - choose docker tags
/*
* Displays input dropdown select containing docker image tags
* Manage Jenkins->Script Approval (required)
*/
node {
stage('chooseDockerTags') {
def image = "IMAGE"
def url = "https://LOCAL-DOCKER-REG:5000/v2/${image}/tags/list"
def list = getDockerImageTags(url)
list = sortReverse(list)
def versions = list.join("\n")
def userInput = input(
id: 'userInput', message: 'Promote:', parameters: [
[$class: 'ChoiceParameterDefinition', choices: versions, description: 'Versions', name: 'version']
]
)
}
}
@NonCPS
def sortReverse(list) {
list.reverse()
}
def getDockerImageTags(url) {
def myjson = getUrl(url)
def json = jsonParse(myjson);
def tags = json.tags
tags
}
def jsonParse(json) {
new groovy.json.JsonSlurper().parseText(json)
}
def getUrl(url) {
sh(returnStdout: true, script: "curl -s ${url} 2>&1 | tee result.json")
def data = readFile('result.json').trim()
data
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment