From 6396cdf715c438e80039c0e3c3e354f4c2f29357 Mon Sep 17 00:00:00 2001 From: MihaiValentinGeorgescu Date: Tue, 28 Nov 2023 17:01:14 +0200 Subject: [PATCH 1/6] test commit jenkins --- fisierPentruTest.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 fisierPentruTest.txt diff --git a/fisierPentruTest.txt b/fisierPentruTest.txt new file mode 100644 index 000000000..66e834ec7 --- /dev/null +++ b/fisierPentruTest.txt @@ -0,0 +1 @@ +sa speram ca a mers pipeline-u:P From 76f9ce0862c01ad8f3eb3ed602c64ca842c6b065 Mon Sep 17 00:00:00 2001 From: MihaiValentinGeorgescu Date: Tue, 28 Nov 2023 17:25:33 +0200 Subject: [PATCH 2/6] al doilea comit --- fisierPentruTest.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fisierPentruTest.txt b/fisierPentruTest.txt index 66e834ec7..6272c8140 100644 --- a/fisierPentruTest.txt +++ b/fisierPentruTest.txt @@ -1 +1,6 @@ sa speram ca a mers pipeline-u:P + + + + +wedfghn From 3bda3fccf75a4c2c520ddfa659ba8d87a2173a81 Mon Sep 17 00:00:00 2001 From: Mihai Georgescu Date: Wed, 29 Nov 2023 11:23:37 +0200 Subject: [PATCH 3/6] Update Jenkinsfile --- Jenkinsfile | 77 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 35a00a297..910c47f8b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,7 +7,6 @@ pipeline { stage('Checkstyle') { steps { sh 'export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64' - sh 'echo $JAVA_HOME' sh 'mvn checkstyle:checkstyle' archiveArtifacts artifacts: 'checkstyle-result.html', onlyIfSuccessful: true } @@ -37,31 +36,62 @@ pipeline { script { def dockerBuildOutput = sh(script: 'docker build -t imagine_spring_petclinic:0.1 .', returnStatus: true) if (dockerBuildOutput == 0) { - echo "Build successful" + echo "Docker image creation successful" } else { - error "Build failed" // Optional: Terminate the pipeline with an error message if the build fails + error "Docker image creation FAILED" // Optional: Terminate the pipeline with an error message if the build fails } } } } - stage('Tag the docker image') { + stage('Tag the docker image for merge request repo - mr') { steps { + echo "now we will 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') + } + } script { - echo "now we will tag the docker image" - sh "docker tag imagine_spring_petclinic:0.1 mihaivalentingeorgescu/mr:0.1" + def imageTag = sh(script: 'docker tag imagine_spring_petclinic:0.1 mihaivalentingeorgescu/mr:0.1', returnStatus: true) + if (imageTag == 0) { + echo "Image tagged successfully" + } else { + error "Image tagging FAILED" + } } } } stage('Login to Dockerhub') { steps { echo "now we will login to dockerhub" - sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin' + script { + def loginDocker = sh(script: 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR -p ', returnStatus: true) + if (loginDocker == 0) { + echo "Login ended successfully" + } else { + error "Login FAILED" + } + } } } - stage('Push to DockerHub') { + stage('Push to DockerHub to merge rewuest repo - mr') { + 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" - sh 'docker push mihaivalentingeorgescu/mr:0.1' + script { + def pushToDocker = sh(script: 'docker push mihaivalentingeorgescu/mr:0.1', returnStatus: true) + if (pushToDocker == 0) { + echo "Push made successfully" + } else { + error "Docker push FAILED" + } + } } } stage('Change stages') { @@ -70,15 +100,40 @@ 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" - sh "docker tag imagine_spring_petclinic:0.1 mihaivalentingeorgescu/main:0.1" + script { + def tagDockerImage = sh(script: 'docker tag imagine_spring_petclinic:0.1 mihaivalentingeorgescu/main:0.1', returnStatus: true) + if (tagDockerImage == 0) { + echo "Docke tag ended successfully" + } else { + error "Docker tag FAILED" + } + } } } stage('Push docker image to main repository') { steps { echo "now we will push the image to the docker main repository" - sh 'docker push mihaivalentingeorgescu/main:0.1' + when { + // Condition to execute the stage on a pull request event + expression { + return env.CHANGE_ID != null + } + script { + def pushDockerImageToMain = sh(script: 'docker push mihaivalentingeorgescu/main:0.1', returnStatus: true) + if (pushDockerImageToMain == 0) { + echo "Docke tag ended successfully" + } else { + error "Docker tag FAILED" + } + } } } } From 6eec52bfcedc6512d1eaefaafcc5309123f515b1 Mon Sep 17 00:00:00 2001 From: Mihai Georgescu Date: Wed, 29 Nov 2023 11:25:24 +0200 Subject: [PATCH 4/6] Update Jenkinsfile --- Jenkinsfile | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 910c47f8b..32af4156c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -43,15 +43,15 @@ pipeline { } } } - stage('Tag the docker image for merge request repo - mr') { - steps { - echo "now we will tag the docker image" - when { + 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 { def imageTag = sh(script: 'docker tag imagine_spring_petclinic:0.1 mihaivalentingeorgescu/mr:0.1', returnStatus: true) if (imageTag == 0) { @@ -66,7 +66,7 @@ pipeline { steps { echo "now we will login to dockerhub" script { - def loginDocker = sh(script: 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR -p ', returnStatus: true) + def loginDocker = sh(script: 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin', returnStatus: true) if (loginDocker == 0) { echo "Login ended successfully" } else { @@ -75,13 +75,13 @@ pipeline { } } } - stage('Push to DockerHub to merge rewuest repo - mr') { + 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') + expression { + return (env.CHANGE_ID == null && env.BRANCH_NAME == 'main') + } } - } steps { echo "now we will push to the docker file" script { @@ -105,7 +105,6 @@ pipeline { expression { return env.CHANGE_ID != null } - } steps { echo "now we will tag the docker image for the main branch" script { @@ -119,13 +118,13 @@ pipeline { } } stage('Push docker image to main repository') { - steps { - echo "now we will push the image to the docker main repository" - when { + 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 { def pushDockerImageToMain = sh(script: 'docker push mihaivalentingeorgescu/main:0.1', returnStatus: true) if (pushDockerImageToMain == 0) { From c6f2a36d3a63e59eff712c9d7495ef986daee978 Mon Sep 17 00:00:00 2001 From: Mihai Georgescu Date: Wed, 29 Nov 2023 14:26:16 +0200 Subject: [PATCH 5/6] Update Jenkinsfile --- Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 32af4156c..9283bcb8a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -105,6 +105,7 @@ pipeline { expression { return env.CHANGE_ID != null } + } steps { echo "now we will tag the docker image for the main branch" script { @@ -123,6 +124,7 @@ pipeline { expression { return env.CHANGE_ID != null } + } steps { echo "now we will push the image to the docker main repository" script { From 74b324f96d33f60854c67708c9753e8bfd9ddbd9 Mon Sep 17 00:00:00 2001 From: Mihai Georgescu Date: Wed, 29 Nov 2023 14:27:05 +0200 Subject: [PATCH 6/6] Update fisierPentruTest.txt --- fisierPentruTest.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fisierPentruTest.txt b/fisierPentruTest.txt index 6272c8140..0a5091842 100644 --- a/fisierPentruTest.txt +++ b/fisierPentruTest.txt @@ -1,5 +1,5 @@ sa speram ca a mers pipeline-u:P - +pipelineu merge sa vedem daca merge merge requestu