diff --git a/Jenkinsfile b/Jenkinsfile index e88234b74..32af4156c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -44,6 +44,12 @@ pipeline { } } 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 { echo "now we will tag the docker image" script { @@ -70,6 +76,12 @@ pipeline { } } 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 { echo "now we will push to the docker file" script { @@ -88,6 +100,11 @@ pipeline { } } 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 { echo "now we will tag the docker image for the main branch" script { @@ -101,6 +118,11 @@ pipeline { } } 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 { echo "now we will push the image to the docker main repository" script {