Update Jenkinsfile

This commit is contained in:
Mihai Georgescu 2023-11-29 11:21:57 +02:00 committed by GitHub
parent 0a9ac99617
commit 7e4a4c6389
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

22
Jenkinsfile vendored
View file

@ -44,6 +44,12 @@ pipeline {
} }
} }
stage('Tag the docker image') { stage('Tag the docker image') {
when {
// Condition to execute the stage when the branch is main
expression {
return (env.CHANGE_ID == null && env.BRANCH_NAME == 'main')
}
}
steps { steps {
echo "now we will tag the docker image" echo "now we will tag the docker image"
script { script {
@ -70,6 +76,12 @@ pipeline {
} }
} }
stage('Push to DockerHub') { stage('Push to DockerHub') {
when {
// Condition to execute the stage when the branch is main
expression {
return (env.CHANGE_ID == null && env.BRANCH_NAME == 'main')
}
}
steps { steps {
echo "now we will push to the docker file" echo "now we will push to the docker file"
script { script {
@ -88,6 +100,11 @@ pipeline {
} }
} }
stage('Tag docker image again for the main repo') { stage('Tag docker image again for the main repo') {
when {
// Condition to execute the stage on a pull request event
expression {
return env.CHANGE_ID != null
}
steps { steps {
echo "now we will tag the docker image for the main branch" echo "now we will tag the docker image for the main branch"
script { script {
@ -101,6 +118,11 @@ pipeline {
} }
} }
stage('Push docker image to main repository') { stage('Push docker image to main repository') {
when {
// Condition to execute the stage on a pull request event
expression {
return env.CHANGE_ID != null
}
steps { steps {
echo "now we will push the image to the docker main repository" echo "now we will push the image to the docker main repository"
script { script {