Issue
I'm trying to list all the tags (GitLab) inside an input choise, but I do not know how to do it.
What I want to do is to be able to select the tag and based on that perform the deploy to different environments.
Thank you.
Solution
I proposes such a solution working in declarative pipeline with dsl:
- stage with download repo
- parse tags based on repo
- stage with choice parameter
CODE:
pipeline {
agent any
stages {
stage('PollSCM') {
steps {
checkout([$class: 'GitSCM', branches: [[name: 'master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'xxx', url: 'repo']]])
script {
tags = sh(script: "git tag --sort=v:refname | tail -5 ", returnStdout: true).trim()
}
}
}
stage('CHOICE TAG') {
steps {
script {
def tag_response = input message: 'blah blah tags',
parameters: [choice(choices: "${tags}", description: 'blah', name: '')]
env.tag_response = tag_response
}
}
}
stage ('echo choose') {
steps {
echo "I choose: '${tag_response}'"
}
}
}
}
Answered By - rafal1337
Answer Checked By - Willingham (JavaFixing Volunteer)