From d30b889cb9f3ba3db93b00633d4199bc3776829c Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 17 Feb 2023 01:06:58 +0100 Subject: [PATCH 01/20] Initial Jenkinsfile --- Jenkinsfile | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..29a498f --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,15 @@ +pipeline { + agent any + options { + // Timeout counter starts AFTER agent is allocated + timeout(time: 30, unit: 'SECONDS') + } + stages { + stage('Example') { + steps { + echo 'Hello World Nikita' + } + } + } +} + From bb83eb9765c2c68b701064d89f2caefa9ba8219d Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 17 Feb 2023 01:27:25 +0100 Subject: [PATCH 02/20] test declarative pipeline with Docket setup --- Jenkinsfile | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 29a498f..afef3b5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,15 +1,21 @@ pipeline { - agent any - options { - // Timeout counter starts AFTER agent is allocated - timeout(time: 30, unit: 'SECONDS') - } + agent none stages { - stage('Example') { + stage('Back-end') { + agent { + docker { image 'maven:3.9.0-eclipse-temurin-11' } + } steps { - echo 'Hello World Nikita' + sh 'mvn --version' } } +// stage('Front-end') { +// agent { +// docker { image 'node:16.13.1-alpine' } +// } +// steps { +// sh 'node --version' +// } +// } } } - From f7845498e5caf3c9bc2938a9ad8eca7c5b70b7ca Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 17 Feb 2023 02:41:13 +0100 Subject: [PATCH 03/20] Simple Jenkins agent with docker and maven ready. --- agent/Dockerfile | 15 +++++++++++++++ agent/build.sh | 4 ++++ 2 files changed, 19 insertions(+) create mode 100644 agent/Dockerfile create mode 100755 agent/build.sh diff --git a/agent/Dockerfile b/agent/Dockerfile new file mode 100644 index 0000000..2c58dee --- /dev/null +++ b/agent/Dockerfile @@ -0,0 +1,15 @@ +FROM jenkins/agent:latest-jdk11 + +ENV PATH="$PATH:/home/jenkins/.local/bin" + +RUN mkdir -p ~/.local/bin \ + # Maven + && curl -L https://dlcdn.apache.org/maven/maven-3/3.9.0/binaries/apache-maven-3.9.0-bin.tar.gz --output maven.tgz \ + && tar xzvf maven.tgz \ + && mv apache-maven-*/* ~/.local/ \ + && rm -rf apache-maven-*/ maven.tgz \ + # Docker + && curl -L https://download.docker.com/linux/static/stable/x86_64/docker-23.0.0.tgz --output docker.tgz \ + && tar xzvf docker.tgz \ + && mv docker/* ~/.local/bin/ \ + && rm -rf docker/ docker.tgz diff --git a/agent/build.sh b/agent/build.sh new file mode 100755 index 0000000..f01c489 --- /dev/null +++ b/agent/build.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +docker build -t nrousseau/jenkins-agent-allinone:1.0 . +docker push nrousseau/jenkins-agent-allinone:1.0 From dadeb1ba322813c52eede57e7dd2d5b6dc014e85 Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 17 Feb 2023 03:08:21 +0100 Subject: [PATCH 04/20] enhance with creds --- Jenkinsfile | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index afef3b5..43430ab 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,21 +1,19 @@ +# https://github.com/CookieFactoryInSpring/demo-module-maven/blob/demo-jenkins/Jenkinsfile + pipeline { - agent none + agent any + environment { + REPO_USER = credentials('artifactory-user-id') + REPO_USER_PWD = credentials('artifactory-apikey-id') + } stages { - stage('Back-end') { - agent { - docker { image 'maven:3.9.0-eclipse-temurin-11' } + stage('Build all') { + when { + expression { env.BRANCH_NAME == 'feature/cicd' } } steps { - sh 'mvn --version' + sh "mvn -Drepo.id=snapshots -Drepo.login=$REPO_USER -Drepo.pwd=$REPO_USER_PWD clean deploy" } } -// stage('Front-end') { -// agent { -// docker { image 'node:16.13.1-alpine' } -// } -// steps { -// sh 'node --version' -// } -// } } } From e3f9b4c603add5c7e531c74213efe100bb27e6fb Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 17 Feb 2023 03:10:16 +0100 Subject: [PATCH 05/20] fix Jenkins comment --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 43430ab..f8a3f34 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,4 +1,4 @@ -# https://github.com/CookieFactoryInSpring/demo-module-maven/blob/demo-jenkins/Jenkinsfile +// https://github.com/CookieFactoryInSpring/demo-module-maven/blob/demo-jenkins/Jenkinsfile pipeline { agent any From a7012d9291364e6628c47de4929889d02211731b Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 17 Feb 2023 03:12:28 +0100 Subject: [PATCH 06/20] Drop When condition --- Jenkinsfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f8a3f34..d61ef95 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,9 +8,6 @@ pipeline { } stages { stage('Build all') { - when { - expression { env.BRANCH_NAME == 'feature/cicd' } - } steps { sh "mvn -Drepo.id=snapshots -Drepo.login=$REPO_USER -Drepo.pwd=$REPO_USER_PWD clean deploy" } From 88bb7b0daa03fd40b5ef396700a1f25694a41baf Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 17 Feb 2023 03:14:53 +0100 Subject: [PATCH 07/20] change directory on build --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index d61ef95..f2d49f3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,7 @@ pipeline { stages { stage('Build all') { steps { - sh "mvn -Drepo.id=snapshots -Drepo.login=$REPO_USER -Drepo.pwd=$REPO_USER_PWD clean deploy" + sh "cd backend && mvn -Drepo.id=snapshots -Drepo.login=$REPO_USER -Drepo.pwd=$REPO_USER_PWD clean deploy" } } } From dd539db134bc1f081b7a5bbad16aef80a9d0102c Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 17 Feb 2023 03:19:04 +0100 Subject: [PATCH 08/20] switch to jdk17 for agent image --- agent/Dockerfile | 2 +- agent/build.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/agent/Dockerfile b/agent/Dockerfile index 2c58dee..6d29621 100644 --- a/agent/Dockerfile +++ b/agent/Dockerfile @@ -1,4 +1,4 @@ -FROM jenkins/agent:latest-jdk11 +FROM jenkins/agent:latest-jdk17 ENV PATH="$PATH:/home/jenkins/.local/bin" diff --git a/agent/build.sh b/agent/build.sh index f01c489..f2fabcc 100755 --- a/agent/build.sh +++ b/agent/build.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -docker build -t nrousseau/jenkins-agent-allinone:1.0 . -docker push nrousseau/jenkins-agent-allinone:1.0 +docker build -t nrousseau/jenkins-agent-allinone:2.0 . +docker push nrousseau/jenkins-agent-allinone:2.0 From 2b33de2f7617ce109feba1e56565defea4fa62b6 Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 17 Feb 2023 03:58:27 +0100 Subject: [PATCH 09/20] add snapshots deployment --- backend/pom.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/pom.xml b/backend/pom.xml index 13de6bb..c0cb7f5 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -124,4 +124,12 @@ + + + snapshots + 0375b9d96ca0-snapshots + http://vmpx17.polytech.unice.fr:8081/artifactory/tcf-libs-snapshot-local + + + From d212dd73df5ee32d748a639d785cbe5dae65c389 Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 17 Feb 2023 04:12:32 +0100 Subject: [PATCH 10/20] enhance with m2 --- Jenkinsfile | 10 ++++++++ agent/Dockerfile | 2 ++ agent/build.sh | 4 ++-- assets/settings.xml | 56 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 assets/settings.xml diff --git a/Jenkinsfile b/Jenkinsfile index f2d49f3..3bdd5ab 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,6 +7,16 @@ pipeline { REPO_USER_PWD = credentials('artifactory-apikey-id') } stages { + stage ('Initialize') { + steps { + sh ''' + echo "PATH = ${PATH}" + echo "M2_HOME = ${M2_HOME}" + cp assets/settings.xml ${M2_HOME}/ + ls -lah ${M2_HOME} + ''' + } + } stage('Build all') { steps { sh "cd backend && mvn -Drepo.id=snapshots -Drepo.login=$REPO_USER -Drepo.pwd=$REPO_USER_PWD clean deploy" diff --git a/agent/Dockerfile b/agent/Dockerfile index 6d29621..8ca6f59 100644 --- a/agent/Dockerfile +++ b/agent/Dockerfile @@ -1,8 +1,10 @@ FROM jenkins/agent:latest-jdk17 ENV PATH="$PATH:/home/jenkins/.local/bin" +ENV M2_HOME="/home/jenkins/.m2" RUN mkdir -p ~/.local/bin \ + && mkdir -p ~/.m2 \ # Maven && curl -L https://dlcdn.apache.org/maven/maven-3/3.9.0/binaries/apache-maven-3.9.0-bin.tar.gz --output maven.tgz \ && tar xzvf maven.tgz \ diff --git a/agent/build.sh b/agent/build.sh index f2fabcc..a576c8e 100755 --- a/agent/build.sh +++ b/agent/build.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -docker build -t nrousseau/jenkins-agent-allinone:2.0 . -docker push nrousseau/jenkins-agent-allinone:2.0 +docker build -t nrousseau/jenkins-agent-allinone:3.0 . +docker push nrousseau/jenkins-agent-allinone:3.0 diff --git a/assets/settings.xml b/assets/settings.xml new file mode 100644 index 0000000..accbc4e --- /dev/null +++ b/assets/settings.xml @@ -0,0 +1,56 @@ + + + + + ${security.getCurrentUsername()} + ${security.getEscapedEncryptedPassword()!"AP6TEELwzYGRiQgnnTBiSuXkJpupULBmFyiGog"} + central + + + ${security.getCurrentUsername()} + ${security.getEscapedEncryptedPassword()!"AP6TEELwzYGRiQgnnTBiSuXkJpupULBmFyiGog"} + snapshots + + + + + + + + false + + central + tcf-libs-release + http://vmpx17.polytech.unice.fr:8081/artifactory/tcf-libs-release + + + + snapshots + tcf-libs-snapshot + http://vmpx17.polytech.unice.fr:8081/artifactory/tcf-libs-snapshot + + + + + + false + + central + tcf-libs-release + http://vmpx17.polytech.unice.fr:8081/artifactory/tcf-libs-release + + + + snapshots + tcf-libs-snapshot + http://vmpx17.polytech.unice.fr:8081/artifactory/tcf-libs-snapshot + + + artifactory + + + + artifactory + + \ No newline at end of file From 477f4131415bee3a2f3b83a9f65378cc7dba0ae1 Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 17 Feb 2023 04:22:11 +0100 Subject: [PATCH 11/20] Add doc to maven lifecycle --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 3bdd5ab..c13ec6b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,4 +1,5 @@ // https://github.com/CookieFactoryInSpring/demo-module-maven/blob/demo-jenkins/Jenkinsfile +// https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html pipeline { agent any From a4e238bd93660b2a8b63108fa4def8ad26247e35 Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 17 Feb 2023 04:42:14 +0100 Subject: [PATCH 12/20] add clean + verify for troubleshoot --- Jenkinsfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index c13ec6b..0855503 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -18,6 +18,11 @@ pipeline { ''' } } + stage('Verify') { + steps { + sh "cd backend && mvn clean verify" + } + } stage('Build all') { steps { sh "cd backend && mvn -Drepo.id=snapshots -Drepo.login=$REPO_USER -Drepo.pwd=$REPO_USER_PWD clean deploy" From 3f88b3caf43474d0d528663abe8d7856d3d6b069 Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 17 Feb 2023 04:43:49 +0100 Subject: [PATCH 13/20] rollback pom change --- backend/pom.xml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/backend/pom.xml b/backend/pom.xml index c0cb7f5..13de6bb 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -124,12 +124,4 @@ - - - snapshots - 0375b9d96ca0-snapshots - http://vmpx17.polytech.unice.fr:8081/artifactory/tcf-libs-snapshot-local - - - From 9dadf9be026b680429677de7713440be68880593 Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 17 Feb 2023 04:45:58 +0100 Subject: [PATCH 14/20] do not push m2 settings --- Jenkinsfile | 3 ++- backend/pom.xml | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0855503..0c1a2bd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,8 +13,9 @@ pipeline { sh ''' echo "PATH = ${PATH}" echo "M2_HOME = ${M2_HOME}" - cp assets/settings.xml ${M2_HOME}/ + #cp assets/settings.xml ${M2_HOME}/ ls -lah ${M2_HOME} + java -version ''' } } diff --git a/backend/pom.xml b/backend/pom.xml index 13de6bb..c0cb7f5 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -124,4 +124,12 @@ + + + snapshots + 0375b9d96ca0-snapshots + http://vmpx17.polytech.unice.fr:8081/artifactory/tcf-libs-snapshot-local + + + From 2cbac1a113d3bc98c18969dd702aa89a96aac9dd Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 17 Feb 2023 04:52:03 +0100 Subject: [PATCH 15/20] use plain token --- Jenkinsfile | 2 +- assets/settings.xml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0c1a2bd..bb1b5dc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,7 @@ pipeline { sh ''' echo "PATH = ${PATH}" echo "M2_HOME = ${M2_HOME}" - #cp assets/settings.xml ${M2_HOME}/ + cp assets/settings.xml ${M2_HOME}/ ls -lah ${M2_HOME} java -version ''' diff --git a/assets/settings.xml b/assets/settings.xml index accbc4e..d03b281 100644 --- a/assets/settings.xml +++ b/assets/settings.xml @@ -3,13 +3,13 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - ${security.getCurrentUsername()} - ${security.getEscapedEncryptedPassword()!"AP6TEELwzYGRiQgnnTBiSuXkJpupULBmFyiGog"} + admin + cmVmdGtuOjAxOjAwMDAwMDAwMDA6YWR2VHBQejQwdXBsZkhoT0RxeWpFZlNpNlc2 central - ${security.getCurrentUsername()} - ${security.getEscapedEncryptedPassword()!"AP6TEELwzYGRiQgnnTBiSuXkJpupULBmFyiGog"} + admin + cmVmdGtuOjAxOjAwMDAwMDAwMDA6YWR2VHBQejQwdXBsZkhoT0RxeWpFZlNpNlc2 snapshots From 140c1eb41745ac7fcdfcf0541571b9e09f8fd6ef Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 17 Feb 2023 05:25:37 +0100 Subject: [PATCH 16/20] down grade to maven 3.6.3 -> https://backstage.forgerock.com/knowledge/kb/article/a15127846 --- agent/Dockerfile | 2 +- agent/build.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/agent/Dockerfile b/agent/Dockerfile index 8ca6f59..c365e0d 100644 --- a/agent/Dockerfile +++ b/agent/Dockerfile @@ -6,7 +6,7 @@ ENV M2_HOME="/home/jenkins/.m2" RUN mkdir -p ~/.local/bin \ && mkdir -p ~/.m2 \ # Maven - && curl -L https://dlcdn.apache.org/maven/maven-3/3.9.0/binaries/apache-maven-3.9.0-bin.tar.gz --output maven.tgz \ + && curl -L https://dlcdn.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz --output maven.tgz \ && tar xzvf maven.tgz \ && mv apache-maven-*/* ~/.local/ \ && rm -rf apache-maven-*/ maven.tgz \ diff --git a/agent/build.sh b/agent/build.sh index a576c8e..f3ebd81 100755 --- a/agent/build.sh +++ b/agent/build.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -docker build -t nrousseau/jenkins-agent-allinone:3.0 . -docker push nrousseau/jenkins-agent-allinone:3.0 +docker build -t nrousseau/jenkins-agent-allinone:4.0 . +docker push nrousseau/jenkins-agent-allinone:4.0 From 1e2440e729ce4a56b009b04f57632f2dc913f15b Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 17 Feb 2023 05:28:53 +0100 Subject: [PATCH 17/20] verify build compat --- Jenkinsfile | 2 +- assets/settings.xml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index bb1b5dc..0c1a2bd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,7 @@ pipeline { sh ''' echo "PATH = ${PATH}" echo "M2_HOME = ${M2_HOME}" - cp assets/settings.xml ${M2_HOME}/ + #cp assets/settings.xml ${M2_HOME}/ ls -lah ${M2_HOME} java -version ''' diff --git a/assets/settings.xml b/assets/settings.xml index d03b281..accbc4e 100644 --- a/assets/settings.xml +++ b/assets/settings.xml @@ -3,13 +3,13 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - admin - cmVmdGtuOjAxOjAwMDAwMDAwMDA6YWR2VHBQejQwdXBsZkhoT0RxeWpFZlNpNlc2 + ${security.getCurrentUsername()} + ${security.getEscapedEncryptedPassword()!"AP6TEELwzYGRiQgnnTBiSuXkJpupULBmFyiGog"} central - admin - cmVmdGtuOjAxOjAwMDAwMDAwMDA6YWR2VHBQejQwdXBsZkhoT0RxeWpFZlNpNlc2 + ${security.getCurrentUsername()} + ${security.getEscapedEncryptedPassword()!"AP6TEELwzYGRiQgnnTBiSuXkJpupULBmFyiGog"} snapshots From ac07f1a6cf37b52f2bb9e3be9ae46b63ca6ee75f Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 17 Feb 2023 05:32:10 +0100 Subject: [PATCH 18/20] push settings --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0c1a2bd..bb1b5dc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,7 @@ pipeline { sh ''' echo "PATH = ${PATH}" echo "M2_HOME = ${M2_HOME}" - #cp assets/settings.xml ${M2_HOME}/ + cp assets/settings.xml ${M2_HOME}/ ls -lah ${M2_HOME} java -version ''' From e09802fe2d79aba436d5cfe29ebee13012da488e Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 17 Feb 2023 05:35:49 +0100 Subject: [PATCH 19/20] simplify jenkinsfile --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index bb1b5dc..c5c497b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,6 +16,7 @@ pipeline { cp assets/settings.xml ${M2_HOME}/ ls -lah ${M2_HOME} java -version + mvn -version ''' } } @@ -26,7 +27,7 @@ pipeline { } stage('Build all') { steps { - sh "cd backend && mvn -Drepo.id=snapshots -Drepo.login=$REPO_USER -Drepo.pwd=$REPO_USER_PWD clean deploy" + sh "cd backend && mvn -Drepo.id=snapshots clean deploy" } } } From ffa8b5e02fd469c6a992cf36765c3502bdd89c4e Mon Sep 17 00:00:00 2001 From: nikita Date: Fri, 17 Feb 2023 05:39:51 +0100 Subject: [PATCH 20/20] plain --- assets/settings.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/assets/settings.xml b/assets/settings.xml index accbc4e..1d2bf0c 100644 --- a/assets/settings.xml +++ b/assets/settings.xml @@ -3,13 +3,13 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - ${security.getCurrentUsername()} - ${security.getEscapedEncryptedPassword()!"AP6TEELwzYGRiQgnnTBiSuXkJpupULBmFyiGog"} + admin + 4UHq2vpt78vKiqa_ central - ${security.getCurrentUsername()} - ${security.getEscapedEncryptedPassword()!"AP6TEELwzYGRiQgnnTBiSuXkJpupULBmFyiGog"} + admin + 4UHq2vpt78vKiqa_ snapshots