Skip to content

Instantly share code, notes, and snippets.

@RHeynsZa
Last active July 23, 2024 13:26
Show Gist options
  • 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()
"""
]
]
]
])
]
)
@RHeynsZa
Copy link
Author

Turns out this is really horrible if you have a lot of images. Cool

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