Last active
July 23, 2024 13:26
-
-
Save RHeynsZa/e93b03b43a92619cff481ed2561c2c39 to your computer and use it in GitHub Desktop.
Jenkins Active Choices for AWS ECR Image Tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Turns out this is really horrible if you have a lot of images. Cool