Skip to content

Instantly share code, notes, and snippets.

@RHeynsZa
Last active August 9, 2023 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RHeynsZa/e93b03b43a92619cff481ed2561c2c39 to your computer and use it in GitHub Desktop.
Save RHeynsZa/e93b03b43a92619cff481ed2561c2c39 to your computer and use it in GitHub Desktop.
Jenkins Active Choices for AWS ECR Image Tags
properties(
[
parameters ([
choice(
name: 'ENVIRONMENT', choices: ['none','dev', 'qa'], description: 'Which environment do you want to deploy to?'
),
[
$class: 'CascadeChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
description: 'Select tag',
filterLength: 1,
filterable: false,
name: 'TAG',
script: [
$class: 'GroovyScript',
script: [
classpath: [],
sandbox: false,
script:
"""
def tags = []
def cmd = "aws ecr describe-images --repository-name <image_name> --region eu-north-1 --filter tagStatus=TAGGED"
def proc = cmd.execute()
proc.waitFor()
def output = proc.in.text
def json = new groovy.json.JsonSlurper().parseText(output)
json.imageDetails.each { image ->
tags.add(image.imageTags[0])
}
return tags.sort().reverse()
"""
]
]
]
])
]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment