Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Abdullah Khabir
meo
Commits
1e705d7c
Commit
1e705d7c
authored
4 months ago
by
Abdullah Khabir
Browse files
Options
Download
Email Patches
Plain Diff
asking user for input
parent
9691df3e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
27 deletions
+15
-27
Jenkinsfile
Jenkinsfile
+15
-27
No files found.
Jenkinsfile
View file @
1e705d7c
...
...
@@ -2,42 +2,30 @@ pipeline {
agent
any
stages
{
stage
(
'
Build
'
)
{
stage
(
'
List and Select Tag
'
)
{
steps
{
script
{
//
G
et
the current commit SHA and take the first 7 characters
def
commitSha
=
env
.
GIT_COMMIT
.
take
(
7
)
//
F
et
ch 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."
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment