From 354238948d22a892f51222cc044298bee0d30fe5 Mon Sep 17 00:00:00 2001 From: Mihai Georgescu Date: Tue, 28 Nov 2023 09:48:19 +0200 Subject: [PATCH] Update Jenkinsfile --- Jenkinsfile | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e80d173e0..44bc2c0b9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,7 +4,7 @@ pipeline { stage('Checkstyle') { steps { sh 'mvn checkstyle:checkstyle' - archiveArtifacts artifacts: 'checkstyle-result.html', onlyIfSuccessful: true + archiveArtifacts artifacts: 'target/checkstyle-result.html', onlyIfSuccessful: true } } stage('Tests') { @@ -16,18 +16,34 @@ pipeline { stage('Build') { steps { echo "now we will begin the build" - sh 'mvn clean package -DskipTests' + script { + def appBuildoutPut = sh (script: 'mvn clean package -Dskiptests') + if (appBuildoutPut == 0) { + echo "build SUCCESSFUL" + } else { + error "Build failed" + } + } } } stage('Create docker image') { steps { echo "now we will begin the creation of the docker image" - sh "docker build -t imagine_spring_petclinic:0.1 ." + script { + def dockerBuildOutput = sh(script: 'docker build -t imagine_spring_petclinic:0.1 .', returnStatus: true) + if (dockerBuildOutput == 0) { + echo "Build successful" + } else { + error "Build failed" // Optional: Terminate the pipeline with an error message if the build fails + } + } } } stage('Tag the docker image') { steps { echo "now we will tag the docker image" + def dockerTag = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim() + echo "The tag used for Docker image: ${dockerTag}" } } stage('Push to DockerHub') {