Update Jenkinsfile

This commit is contained in:
Mihai Georgescu 2023-12-04 15:55:28 +02:00 committed by GitHub
parent 5e2ae023e8
commit 73f9c65d76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

18
Jenkinsfile vendored
View file

@ -4,6 +4,7 @@ pipeline {
DOCKERHUB_CREDENTIALS = credentials('mihaivalentingeorgescu-dockerhub') DOCKERHUB_CREDENTIALS = credentials('mihaivalentingeorgescu-dockerhub')
} }
stages { stages {
stage('Checkstyle') { stage('Checkstyle') {
steps { steps {
sh 'export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64' sh 'export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64'
@ -32,7 +33,7 @@ pipeline {
} }
stage('Create docker image') { stage('Create docker image') {
steps { steps {
echo "now we will begin the creation of the docker image " echo " now we will begin the creation of the docker image "
script { script {
def dockerBuildOutput = sh(script: 'docker build -t imagine_spring_petclinic:0.1 .', returnStatus: true) def dockerBuildOutput = sh(script: 'docker build -t imagine_spring_petclinic:0.1 .', returnStatus: true)
if (dockerBuildOutput == 0) { if (dockerBuildOutput == 0) {
@ -45,8 +46,7 @@ pipeline {
} }
stage('Tag the docker image') { stage('Tag the docker image') {
when { when {
// Condition to execute the stage when the branch is mai expression { currentBuild.changeSets == null }
changeRequest()
} }
steps { steps {
echo "now we will tag the docker image " echo "now we will tag the docker image "
@ -75,8 +75,7 @@ pipeline {
} }
stage('Push to DockerHub') { stage('Push to DockerHub') {
when { when {
// Condition to execute the stage when the branch is main expression { currentBuild.changeSets == null }
changeRequest()
} }
steps { steps {
echo "now we will push to the docker file" echo "now we will push to the docker file"
@ -97,10 +96,7 @@ pipeline {
} }
stage('Tag docker image again for the main repo') { stage('Tag docker image again for the main repo') {
when { when {
// Condition to execute the stage when the branch is 'main' expression { currentBuild.changeSets != null }
not {
changeRequest()
}
} }
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"
@ -117,9 +113,7 @@ pipeline {
stage('Push docker image to main repository') { stage('Push docker image to main repository') {
when { when {
// Condition to execute the stage when the branch is 'main' // Condition to execute the stage when the branch is 'main'
not { expression { currentBuild.changeSets != null }
changeRequest()
}
} }
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"