Last active
January 22, 2026 20:34
-
-
Save AlexAtkinson/fb113e9001058b459d8a69bb52b7a18d to your computer and use it in GitHub Desktop.
Jenkinsfile - Populate input field with Docker tags (ECR)
This file contains hidden or 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
| // #!/usr/bin/env groovy | |
| // Requires the following envars: | |
| // - SRC_ENV : The source env/awscli profile for of the ecr repo to pull from. | |
| // - ECR_REPO : The name of the ecr repository to pull from. | |
| // - AWS_REGION : The AWS Region of the source repo | |
| // This assuems the jenkins host is setup with aws profiles. | |
| // | |
| // Note: Most valuable for graduated/promotion-driven product SDLC. | |
| // This posture mitigates the risk of unqualified product reaching PROD. | |
| // DEV will have every tag available for deployment. | |
| // QA will have only those the DEVs submit for QA available. | |
| // STAG will have only those that pass QA available. | |
| // RPOD will have only those that pass STAG activities (perf/pentest/etc.,). | |
| def getOptions() { | |
| return (["/bin/bash", "-c", "aws --profile ${SRC_ENV} --region ${AWS_REGION} ecr describe-images --repository-name ${env.ECR_REPO} --query 'reverse(sort_by(imageDetails,& imagePushedAt))[0:24].imageTags' --output text | sed 's/[[:blank:]]/\\n/g' | sed '/latest/d; /SNAPSHOT/d' | sed ':a;N;\$!ba;s/\\n/ /g; s/\\s\$/\\n/g'"].execute().text.tokenize()) | |
| } | |
| pipeline { | |
| agent any | |
| stages { | |
| stage('Version') { | |
| steps { | |
| script { | |
| env.VERSION = input message: 'User input required', ok: 'GO!', | |
| parameters: [choice(name: 'VERSION', choices: getOptions(), description: 'Select the VERSION.')] | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment