Commit 1e705d7c authored by Abdullah Khabir's avatar Abdullah Khabir
Browse files

asking user for input

parent 9691df3e
......@@ -2,42 +2,30 @@ pipeline {
agent any
stages {
stage('Build') {
stage('List and Select Tag') {
steps {
script {
// Get the current commit SHA and take the first 7 characters
def commitSha = env.GIT_COMMIT.take(7)
// Fetch all tags from Git
def tags = sh(script: "git tag", returnStdout: true).trim().split("\n")
// Tag the Docker image with the short commit SHA
sh """
docker buildx build -t helloworld:${commitSha} .
docker run --rm helloworld:${commitSha}
"""
if (tags.size() == 0) {
error("No tags found in the repository.")
}
// Show dropdown for user to select a tag
def selectedTag = input message: 'Select a Git tag to deploy:',
parameters: [choice(name: 'TAG', choices: tags.join("\n"), description: 'Available Git tags')]
// Print the selected tag
echo "You selected the tag: ${selectedTag}"
}
}
}
}
post {
failure {
script {
// Get the last successful build
// def lastSuccessfulBuild = currentBuild.rawBuild.getPreviousSuccessfulBuild()
// if (lastSuccessfulBuild) {
// Redeploy the last successful build
// echo "Redeploying build #${lastSuccessfulBuild.getId()}..."
// echo "Last successful build was #${lastSuccessfulBuild.getNumber()}"
// Example: Call your deployment script or steps here
// sh "deploy-script.sh ${lastSuccessfulBuild.getNumber()}"
// } else {
// error "No successful build found to deploy."
// }
def previousCommitSha = sh(script: 'git rev-parse HEAD~1', returnStdout: true).trim()
def shortPreviousCommitSha = previousCommitSha.take(7)
sh "docker run --rm helloworld:${shortPreviousCommitSha}"
}
always {
echo "Pipeline execution finished."
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment