Skip to content

Instantly share code, notes, and snippets.

@m-x-k
Created November 16, 2016 22:05
Show Gist options
  • Save m-x-k/15d74f6b5cd1e7531b9b1130710c1546 to your computer and use it in GitHub Desktop.
Save m-x-k/15d74f6b5cd1e7531b9b1130710c1546 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
}
@mniazi-nisum-com
Copy link

Hello I am getting NUL in tags. any Idea why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment