Skip to content

Instantly share code, notes, and snippets.

@AlexAtkinson
Created August 25, 2022 20:38
Show Gist options
  • Save AlexAtkinson/fb113e9001058b459d8a69bb52b7a18d to your computer and use it in GitHub Desktop.
Save AlexAtkinson/fb113e9001058b459d8a69bb52b7a18d to your computer and use it in GitHub Desktop.
Jenkinsfile Groovy snippet for populating a user input with docker image tags (ECR).
#!/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.
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