From 3b72c450cc72a13a846c806956224fd612f20457 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Thu, 30 Jan 2020 15:34:03 +0100 Subject: [PATCH 01/42] add quality issues to code branch --- my-app.iml | 16 +++++++++++++++ src/main/java/com/mycompany/app/App.java | 25 +++++++++++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 my-app.iml diff --git a/my-app.iml b/my-app.iml new file mode 100644 index 0000000000..e802c7b850 --- /dev/null +++ b/my-app.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/mycompany/app/App.java b/src/main/java/com/mycompany/app/App.java index 5a6d57214d..cfddd83e7f 100644 --- a/src/main/java/com/mycompany/app/App.java +++ b/src/main/java/com/mycompany/app/App.java @@ -7,15 +7,34 @@ public class App { private final String message = "Hello World!"; + public String msg1; + public String msg2; - public App() {} + + public App() { + msg1 = "one"; + msg2="two"; + } public static void main(String[] args) { - System.out.println(new App().getMessage()); + App myApp = new App(); + try { + System.out.println(myApp.getMessage()); + } catch (InterruptedException e) { + e.printStackTrace(); + } } - private final String getMessage() { + private final String getMessage() throws InterruptedException { + synchronized (this.msg1) { + // threadB can't enter this block to request this.mon2 lock & release threadA + synchronized (this.msg2) { + this.msg2.wait(); // Noncompliant; threadA is stuck here holding lock on this.mon1 + } + } + return message; } + } From 79717703c5d604ff5d324e4b9793fac2a5b7bc4d Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Thu, 30 Jan 2020 17:11:36 +0100 Subject: [PATCH 02/42] add branch name to pipeline mvn cmd --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 83d667223c..1dac6c7b02 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -11,7 +11,7 @@ pipeline { stage('Build') { steps { withSonarQubeEnv(installationName: 'ngrok syco') { - sh 'mvn -X -B -DskipTests clean package sonar:sonar' + sh 'mvn -X -B -Dsonar.branch.name=$GIT_BRANCH -DskipTests clean package sonar:sonar' } } } From c920aec0163b96873d32f7b3a28c93ada811b369 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Thu, 30 Jan 2020 17:58:15 +0100 Subject: [PATCH 03/42] master branch condition in JenkinsFile --- Jenkinsfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1dac6c7b02..d6cec1a2b0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -11,7 +11,10 @@ pipeline { stage('Build') { steps { withSonarQubeEnv(installationName: 'ngrok syco') { - sh 'mvn -X -B -Dsonar.branch.name=$GIT_BRANCH -DskipTests clean package sonar:sonar' + if($GIT_BRANCH == "master") + sh 'mvn -X -B -DskipTests clean package sonar:sonar' + else + sh 'mvn -X -B -Dsonar.branch.name=$GIT_BRANCH -DskipTests clean package sonar:sonar' } } } From 88dfc0668b69fc3a29c490f284f71a6f95637d0d Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Fri, 31 Jan 2020 12:08:23 +0100 Subject: [PATCH 04/42] report JenkinsFile fix done on master --- Jenkinsfile | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d6cec1a2b0..b8f5613927 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,3 +1,9 @@ +if (env.BRANCH_NAME == 'master') + mybranch = '' +else + mybranch = env.BRANCH_NAME + + pipeline { agent { docker { @@ -10,12 +16,9 @@ pipeline { stages { stage('Build') { steps { - withSonarQubeEnv(installationName: 'ngrok syco') { - if($GIT_BRANCH == "master") - sh 'mvn -X -B -DskipTests clean package sonar:sonar' - else - sh 'mvn -X -B -Dsonar.branch.name=$GIT_BRANCH -DskipTests clean package sonar:sonar' - } + withSonarQubeEnv(installationName: 'ngrok syco') { + sh 'mvn -X -B -Dsonar.branch.name=${mybranch} -DskipTests clean package sonar:sonar' + } } } stage('Test') { From b35b56e11150ea25fda86b28cc4620963d07e8ab Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Tue, 4 Feb 2020 10:13:37 +0100 Subject: [PATCH 05/42] fixed locked unitary tests --- src/main/java/com/mycompany/app/App.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mycompany/app/App.java b/src/main/java/com/mycompany/app/App.java index cfddd83e7f..a79fe4567b 100644 --- a/src/main/java/com/mycompany/app/App.java +++ b/src/main/java/com/mycompany/app/App.java @@ -25,14 +25,17 @@ public static void main(String[] args) { } } - private final String getMessage() throws InterruptedException { + private final String getMessage(boolean isSync) throws InterruptedException { synchronized (this.msg1) { // threadB can't enter this block to request this.mon2 lock & release threadA synchronized (this.msg2) { this.msg2.wait(); // Noncompliant; threadA is stuck here holding lock on this.mon1 } } + return message; + } + private final String getMessage() throws InterruptedException { return message; } From ebdcd17889fb66eb3009041fa44c4cc3d98681fc Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Tue, 4 Feb 2020 13:57:45 +0100 Subject: [PATCH 06/42] try to dump JenkinsFile env --- Jenkinsfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index b8f5613927..31629384a3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,6 +3,9 @@ if (env.BRANCH_NAME == 'master') else mybranch = env.BRANCH_NAME +node { + echo "$env" +} pipeline { agent { From 30eba7de6e7b3a16c919602a953dc73749e1fd44 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Tue, 4 Feb 2020 14:09:13 +0100 Subject: [PATCH 07/42] try to dump JenkinsFile env 2 --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 31629384a3..876241f914 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,7 +4,8 @@ else mybranch = env.BRANCH_NAME node { - echo "$env" + echo "hello here" + env.dump() } pipeline { From 25a0ec1a991840bb5c3042b5ade7a0fca59b811b Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Tue, 4 Feb 2020 14:30:57 +0100 Subject: [PATCH 08/42] try to dump JenkinsFile env 3 --- Jenkinsfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 876241f914..2a7262ab60 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,8 +4,11 @@ else mybranch = env.BRANCH_NAME node { - echo "hello here" - env.dump() + echo "Branch name" + echo env.BRANCH_NAME + echo env.CHANGE_ID + echo env.CHANGE_BRANCH + echo env.CHANGE_TARGET } pipeline { From ee8d1c4c8644ae83e7aaf04b60ef8d5bd4e4f4c0 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Tue, 4 Feb 2020 15:00:32 +0100 Subject: [PATCH 09/42] try to build PR analysis --- Jenkinsfile | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2a7262ab60..13beb78058 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,16 +1,33 @@ if (env.BRANCH_NAME == 'master') - mybranch = '' + myBranch = '' else - mybranch = env.BRANCH_NAME + myBranch = env.BRANCH_NAME node { - echo "Branch name" + echo "Jenkins variables" echo env.BRANCH_NAME + echo myBranch echo env.CHANGE_ID echo env.CHANGE_BRANCH echo env.CHANGE_TARGET } +if(env.CHANGE_ID != null) // PR analysis + mvnCmdLine = 'mvn -X -B -DskipTests \ + -Dsonar.pullrequest.key=${env.CHANGE_ID} \ + -Dsonar.pullrequest.branch=${mybranch} \ + -Dsonar.pullrequest.base=${env.CHANGE_TARGET} \ + clean package sonar:sonar' +else // regular branch analysis + mvnCmdLine = 'mvn -X -B -DskipTests \ + -Dsonar.branch.name=${mybranch} \ + clean package sonar:sonar' + +node { + echo "My command line:" + echo mvnCmdLine +} + pipeline { agent { docker { @@ -24,7 +41,7 @@ pipeline { stage('Build') { steps { withSonarQubeEnv(installationName: 'ngrok syco') { - sh 'mvn -X -B -Dsonar.branch.name=${mybranch} -DskipTests clean package sonar:sonar' + sh '${mvnCmdLine}' } } } From 23c82b2e5a0704b08acc024256279920f804276a Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Tue, 4 Feb 2020 15:05:23 +0100 Subject: [PATCH 10/42] try to build PR analysis 2 --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 13beb78058..6d4062feac 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -15,12 +15,12 @@ node { if(env.CHANGE_ID != null) // PR analysis mvnCmdLine = 'mvn -X -B -DskipTests \ -Dsonar.pullrequest.key=${env.CHANGE_ID} \ - -Dsonar.pullrequest.branch=${mybranch} \ + -Dsonar.pullrequest.branch=${myBranch} \ -Dsonar.pullrequest.base=${env.CHANGE_TARGET} \ clean package sonar:sonar' else // regular branch analysis mvnCmdLine = 'mvn -X -B -DskipTests \ - -Dsonar.branch.name=${mybranch} \ + -Dsonar.branch.name=${myBÒranch} \ clean package sonar:sonar' node { From 104e426225a781637e9e5706ccd2e5aae281d6ef Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Tue, 4 Feb 2020 15:19:56 +0100 Subject: [PATCH 11/42] try to build PR analysis 3 --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6d4062feac..3348db563f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -20,7 +20,7 @@ if(env.CHANGE_ID != null) // PR analysis clean package sonar:sonar' else // regular branch analysis mvnCmdLine = 'mvn -X -B -DskipTests \ - -Dsonar.branch.name=${myBÒranch} \ + -Dsonar.branch.name=${myBranch} \ clean package sonar:sonar' node { From 07c680ba6ccfd334958565cf102d13f7e94afae3 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Tue, 4 Feb 2020 17:00:04 +0100 Subject: [PATCH 12/42] try to build PR analysis 4 --- Jenkinsfile | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3348db563f..1faa2fd7c8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -19,9 +19,16 @@ if(env.CHANGE_ID != null) // PR analysis -Dsonar.pullrequest.base=${env.CHANGE_TARGET} \ clean package sonar:sonar' else // regular branch analysis - mvnCmdLine = 'mvn -X -B -DskipTests \ + mvnCmdLine = "mvn -X -B -DskipTests \ -Dsonar.branch.name=${myBranch} \ - clean package sonar:sonar' + clean package sonar:sonar" + +mvnCmdLine2 = "mvn -X -B -DskipTests \ + -Dsonar.branch.name=${env.BRANCH_NAME} \ + clean package sonar:sonar" +mvnCmdLine3 = "mvn -X -B -DskipTests \ + -Dsonar.branch.name=$myBranch \ + clean package sonar:sonar" node { echo "My command line:" From 465abcd938dc9a8b8e6768a0ded3b94a2fb0939f Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Tue, 4 Feb 2020 17:09:56 +0100 Subject: [PATCH 13/42] try to build PR analysis 5 --- Jenkinsfile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1faa2fd7c8..ee3ec0ca90 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,22 +13,22 @@ node { } if(env.CHANGE_ID != null) // PR analysis - mvnCmdLine = 'mvn -X -B -DskipTests \ + mvnCmdLine = "mvn -X -B -DskipTests \ -Dsonar.pullrequest.key=${env.CHANGE_ID} \ -Dsonar.pullrequest.branch=${myBranch} \ -Dsonar.pullrequest.base=${env.CHANGE_TARGET} \ - clean package sonar:sonar' + clean package sonar:sonar" else // regular branch analysis mvnCmdLine = "mvn -X -B -DskipTests \ -Dsonar.branch.name=${myBranch} \ clean package sonar:sonar" -mvnCmdLine2 = "mvn -X -B -DskipTests \ - -Dsonar.branch.name=${env.BRANCH_NAME} \ - clean package sonar:sonar" -mvnCmdLine3 = "mvn -X -B -DskipTests \ - -Dsonar.branch.name=$myBranch \ - clean package sonar:sonar" +// mvnCmdLine2 = "mvn -X -B -DskipTests \ +// -Dsonar.branch.name=${env.BRANCH_NAME} \ +// clean package sonar:sonar" +// mvnCmdLine3 = "mvn -X -B -DskipTests \ +// -Dsonar.branch.name=$myBranch \ +// clean package sonar:sonar" node { echo "My command line:" @@ -48,7 +48,7 @@ pipeline { stage('Build') { steps { withSonarQubeEnv(installationName: 'ngrok syco') { - sh '${mvnCmdLine}' + sh "${mvnCmdLine}" } } } From b923272dd5dc385e998364e3a46e6ee5bcbe8e8c Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Tue, 4 Feb 2020 17:41:01 +0100 Subject: [PATCH 14/42] try to build PR analysis 6 --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index ee3ec0ca90..9debbbbf10 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -48,7 +48,7 @@ pipeline { stage('Build') { steps { withSonarQubeEnv(installationName: 'ngrok syco') { - sh "${mvnCmdLine}" + sh '"${mvnCmdLine}"' } } } From dc1d6f1e4e7563f1d363cdf3b3479bb493a1b03a Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Tue, 4 Feb 2020 17:50:41 +0100 Subject: [PATCH 15/42] Revert "try to build PR analysis 6" This reverts commit b923272dd5dc385e998364e3a46e6ee5bcbe8e8c. --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 9debbbbf10..ee3ec0ca90 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -48,7 +48,7 @@ pipeline { stage('Build') { steps { withSonarQubeEnv(installationName: 'ngrok syco') { - sh '"${mvnCmdLine}"' + sh "${mvnCmdLine}" } } } From f4e1219c88a50fbd2c6571663bad025a84734f76 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource <59280694+sylvain-combe-sonarsource@users.noreply.github.com> Date: Fri, 28 Feb 2020 12:31:27 +0100 Subject: [PATCH 16/42] Add fetch of master for sonar scanner comparison --- Jenkinsfile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index fbeb09fe81..895de57cb3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -48,7 +48,11 @@ pipeline { stage('Build') { steps { withSonarQubeEnv(installationName: 'ngrok syco') { - sh "${mvnCmdLine}" + script { + // fetch master from origin so sonar scanner comparison works + sh "git fetch --no-tags ${GIT_URL} +refs/heads/master:refs/remotes/origin/master" + sh "${mvnCmdLine}" + } } } } @@ -68,4 +72,4 @@ pipeline { } } } -} \ No newline at end of file +} From 1df2a088fb794fda5d261d78884a4ae3ecb55b2a Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource <59280694+sylvain-combe-sonarsource@users.noreply.github.com> Date: Fri, 28 Feb 2020 14:28:58 +0100 Subject: [PATCH 17/42] change docker image get git inside! --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 895de57cb3..6bbb60da0e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -38,7 +38,7 @@ node { pipeline { agent { docker { - image 'maven:3-alpine' + image 'masstroy/alpine-docker-java-maven' } } options { From 35a8e79929474c3bb0645e3e69e97de684ae2646 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Fri, 28 Feb 2020 14:37:40 +0100 Subject: [PATCH 18/42] Fix JenkinsFile conflict --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 6bbb60da0e..1ae478e25d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -48,6 +48,7 @@ pipeline { stage('Build') { steps { withSonarQubeEnv(installationName: 'ngrok syco') { + sh "${mvnCmdLine}" script { // fetch master from origin so sonar scanner comparison works sh "git fetch --no-tags ${GIT_URL} +refs/heads/master:refs/remotes/origin/master" From ea7bdd460d445c8543ae79810ffe368afd9a9e8c Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource <59280694+sylvain-combe-sonarsource@users.noreply.github.com> Date: Wed, 22 Apr 2020 14:24:58 +0200 Subject: [PATCH 19/42] Align Jenkinsfile on master branch one --- Jenkinsfile | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1ae478e25d..5fac1815c7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -38,23 +38,30 @@ node { pipeline { agent { docker { - image 'masstroy/alpine-docker-java-maven' + // image 'masstroy/alpine-docker-java-maven' + image 'maven:3-alpine' + args '-v $HOME/.m2:/root/.m2' } } options { skipStagesAfterUnstable() } stages { + stage('SCM') { + steps { + git 'https://github.com/sylvain-combe-sonarsource/simple-java-maven-app.git' + } + } stage('Build') { steps { - withSonarQubeEnv(installationName: 'ngrok syco') { - sh "${mvnCmdLine}" - script { + withSonarQubeEnv(installationName: 'SQ82') { + // script { // fetch master from origin so sonar scanner comparison works - sh "git fetch --no-tags ${GIT_URL} +refs/heads/master:refs/remotes/origin/master" - sh "${mvnCmdLine}" - } - } + // sh "git fetch --no-tags ${GIT_URL} +refs/heads/master:refs/remotes/origin/master" + // sh "${mvnCmdLine}" + sh 'mvn clean package sonar:sonar' + // } + } } } stage('Test') { From 1c739018cfdd179466e243df712174424a6ffe94 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource <59280694+sylvain-combe-sonarsource@users.noreply.github.com> Date: Wed, 22 Apr 2020 14:37:46 +0200 Subject: [PATCH 20/42] Back to branch and PT analysis parameters --- Jenkinsfile | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5fac1815c7..a18c14d7dd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -23,13 +23,6 @@ else // regular branch analysis -Dsonar.branch.name=${myBranch} \ clean package sonar:sonar" -// mvnCmdLine2 = "mvn -X -B -DskipTests \ -// -Dsonar.branch.name=${env.BRANCH_NAME} \ -// clean package sonar:sonar" -// mvnCmdLine3 = "mvn -X -B -DskipTests \ -// -Dsonar.branch.name=$myBranch \ -// clean package sonar:sonar" - node { echo "My command line:" echo mvnCmdLine @@ -58,8 +51,8 @@ pipeline { // script { // fetch master from origin so sonar scanner comparison works // sh "git fetch --no-tags ${GIT_URL} +refs/heads/master:refs/remotes/origin/master" - // sh "${mvnCmdLine}" - sh 'mvn clean package sonar:sonar' + sh "${mvnCmdLine}" + // sh 'mvn clean package sonar:sonar' // } } } From e920809b1bfc5fd87c6599fefd3123c2c19b7b45 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource <59280694+sylvain-combe-sonarsource@users.noreply.github.com> Date: Wed, 22 Apr 2020 14:58:13 +0200 Subject: [PATCH 21/42] Fix git branch and PR code analyzed --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index a18c14d7dd..8ee06b5ce3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -42,7 +42,8 @@ pipeline { stages { stage('SCM') { steps { - git 'https://github.com/sylvain-combe-sonarsource/simple-java-maven-app.git' + // git 'https://github.com/sylvain-combe-sonarsource/simple-java-maven-app.git' + sh "git fetch --no-tags ${GIT_URL} +refs/heads/master:refs/remotes/origin/master" } } stage('Build') { From b6eb4cf03d05a374dae7baa9767e2d04ce331a36 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource <59280694+sylvain-combe-sonarsource@users.noreply.github.com> Date: Wed, 22 Apr 2020 15:00:08 +0200 Subject: [PATCH 22/42] need git commands again in docker container --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8ee06b5ce3..20a8e342d9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -31,8 +31,8 @@ node { pipeline { agent { docker { - // image 'masstroy/alpine-docker-java-maven' - image 'maven:3-alpine' + image 'masstroy/alpine-docker-java-maven' + // image 'maven:3-alpine' args '-v $HOME/.m2:/root/.m2' } } From 3093490b7f7bcb0f5e7e0d13ca2c6f50a07fa84f Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource <59280694+sylvain-combe-sonarsource@users.noreply.github.com> Date: Wed, 22 Apr 2020 15:12:07 +0200 Subject: [PATCH 23/42] do I need a git command at all --- Jenkinsfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 20a8e342d9..d9eafe5526 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -31,8 +31,8 @@ node { pipeline { agent { docker { - image 'masstroy/alpine-docker-java-maven' - // image 'maven:3-alpine' + // image 'masstroy/alpine-docker-java-maven' + image 'maven:3-alpine' args '-v $HOME/.m2:/root/.m2' } } @@ -43,7 +43,8 @@ pipeline { stage('SCM') { steps { // git 'https://github.com/sylvain-combe-sonarsource/simple-java-maven-app.git' - sh "git fetch --no-tags ${GIT_URL} +refs/heads/master:refs/remotes/origin/master" + // sh "git fetch --no-tags ${GIT_URL} +refs/heads/master:refs/remotes/origin/master" + sh "echo ${GIT_URL}" } } stage('Build') { From 57aab0fc84cd4eacad13f18855757c99c2c318fe Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Wed, 22 Apr 2020 15:24:15 +0200 Subject: [PATCH 24/42] align project keys --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index d0a3e54a9d..5d9ce1cea3 100644 --- a/pom.xml +++ b/pom.xml @@ -42,5 +42,6 @@ 1.8 1.8 + sylvain-combe-sonarsource_simple-java-maven-app From a2522283cfc19aea5be6f34c94fce417199a2e92 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Wed, 22 Apr 2020 15:27:33 +0200 Subject: [PATCH 25/42] resolve conflict on pom.xml --- pom.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pom.xml b/pom.xml index 5d9ce1cea3..f7eebfb4b3 100644 --- a/pom.xml +++ b/pom.xml @@ -43,5 +43,8 @@ 1.8 1.8 sylvain-combe-sonarsource_simple-java-maven-app + sylvain-combe-sonarsource + https://sonarcloud.io + d58f0d63d88254491a09164a0deb397298a99f6e From 432b74652d602744ddc0c0c59b34607fe429f589 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Wed, 22 Apr 2020 15:57:36 +0200 Subject: [PATCH 26/42] add quality gate status check --- Jenkinsfile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index d9eafe5526..f28be88229 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -74,5 +74,14 @@ pipeline { sh './jenkins/scripts/deliver.sh' } } + stage("Quality Gate") { + steps { + timeout(time: 1, unit: 'HOURS') { + // Parameter indicates whether to set pipeline to UNSTABLE if Quality Gate fails + // true = set pipeline to UNSTABLE, false = don't + waitForQualityGate abortPipeline: true + } + } + } } } From 7c4de5dcfd7e2a52be8dbd0fa1835b940151f4c0 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Wed, 22 Apr 2020 17:38:04 +0200 Subject: [PATCH 27/42] new attempt with no analysis parameter --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f28be88229..9e2a2cdac3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -53,8 +53,8 @@ pipeline { // script { // fetch master from origin so sonar scanner comparison works // sh "git fetch --no-tags ${GIT_URL} +refs/heads/master:refs/remotes/origin/master" - sh "${mvnCmdLine}" - // sh 'mvn clean package sonar:sonar' + // sh "${mvnCmdLine}" + sh 'mvn clean package sonar:sonar' // } } } From 03b6fcfa8a320d86304518bd5a0a74720071ce88 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Wed, 22 Apr 2020 17:43:16 +0200 Subject: [PATCH 28/42] add cache for plugins --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 9e2a2cdac3..0fd7102920 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -34,6 +34,7 @@ pipeline { // image 'masstroy/alpine-docker-java-maven' image 'maven:3-alpine' args '-v $HOME/.m2:/root/.m2' + args '-v $HOME/.sonar/cache:/root/.sonar/cache' } } options { From 544d798ba568a4b800bf69596a3835d32222d845 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Wed, 22 Apr 2020 17:44:59 +0200 Subject: [PATCH 29/42] use volume mount for caches --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0fd7102920..ee8ff57c8c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -33,8 +33,8 @@ pipeline { docker { // image 'masstroy/alpine-docker-java-maven' image 'maven:3-alpine' - args '-v $HOME/.m2:/root/.m2' - args '-v $HOME/.sonar/cache:/root/.sonar/cache' + args '-v mavencache:/root/.m2' + args '-v sonarcache:/root/.sonar/cache' } } options { From abed2e34ce7935852f0fdfcb65f56a885f41152a Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Wed, 22 Apr 2020 17:46:49 +0200 Subject: [PATCH 30/42] mandatory parameters back --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ee8ff57c8c..cac073da7d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -54,8 +54,8 @@ pipeline { // script { // fetch master from origin so sonar scanner comparison works // sh "git fetch --no-tags ${GIT_URL} +refs/heads/master:refs/remotes/origin/master" - // sh "${mvnCmdLine}" - sh 'mvn clean package sonar:sonar' + sh "${mvnCmdLine}" + // sh 'mvn clean package sonar:sonar' // } } } From e1e37c1810ebc4d773996df73e6a2c9a3d8b4015 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Wed, 22 Apr 2020 18:04:47 +0200 Subject: [PATCH 31/42] user home tweaks --- Jenkinsfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index cac073da7d..f785270960 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,10 +17,12 @@ if(env.CHANGE_ID != null) // PR analysis -Dsonar.pullrequest.key=${env.CHANGE_ID} \ -Dsonar.pullrequest.branch=${myBranch} \ -Dsonar.pullrequest.base=${env.CHANGE_TARGET} \ + -Duser.home=$HOME \ clean package sonar:sonar" else // regular branch analysis mvnCmdLine = "mvn -X -B -DskipTests \ -Dsonar.branch.name=${myBranch} \ + -Duser.home=$HOME \ clean package sonar:sonar" node { @@ -33,8 +35,8 @@ pipeline { docker { // image 'masstroy/alpine-docker-java-maven' image 'maven:3-alpine' - args '-v mavencache:/root/.m2' - args '-v sonarcache:/root/.sonar/cache' + args '-v mavencache:$HOME/.m2' \ + '-v sonarcache:$HOME/.sonar/cache' } } options { From c9a4c10cb01134d0d818322a71ded7ef96ee79e2 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Wed, 22 Apr 2020 18:07:54 +0200 Subject: [PATCH 32/42] fix args --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f785270960..8b24898131 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -35,8 +35,8 @@ pipeline { docker { // image 'masstroy/alpine-docker-java-maven' image 'maven:3-alpine' - args '-v mavencache:$HOME/.m2' \ - '-v sonarcache:$HOME/.sonar/cache' + args '-v mavencache:$HOME/.m2 \ + -v sonarcache:$HOME/.sonar/cache' } } options { From 2f5f359a493c4a1f4b220eb40e273eca34400862 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Wed, 22 Apr 2020 18:12:35 +0200 Subject: [PATCH 33/42] HOME not existing --- Jenkinsfile | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8b24898131..3f54f4e6a0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,12 +17,10 @@ if(env.CHANGE_ID != null) // PR analysis -Dsonar.pullrequest.key=${env.CHANGE_ID} \ -Dsonar.pullrequest.branch=${myBranch} \ -Dsonar.pullrequest.base=${env.CHANGE_TARGET} \ - -Duser.home=$HOME \ clean package sonar:sonar" else // regular branch analysis mvnCmdLine = "mvn -X -B -DskipTests \ -Dsonar.branch.name=${myBranch} \ - -Duser.home=$HOME \ clean package sonar:sonar" node { @@ -35,8 +33,8 @@ pipeline { docker { // image 'masstroy/alpine-docker-java-maven' image 'maven:3-alpine' - args '-v mavencache:$HOME/.m2 \ - -v sonarcache:$HOME/.sonar/cache' + args '-v maven-cache:$HOME/.m2 \ + -v sonar-cache:$HOME/.sonar/cache' } } options { @@ -56,7 +54,7 @@ pipeline { // script { // fetch master from origin so sonar scanner comparison works // sh "git fetch --no-tags ${GIT_URL} +refs/heads/master:refs/remotes/origin/master" - sh "${mvnCmdLine}" + sh "${mvnCmdLine} -Duser.home=$HOME" // sh 'mvn clean package sonar:sonar' // } } From b6576cd2df8c366a55b447200af85e3f96877164 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Wed, 22 Apr 2020 18:15:09 +0200 Subject: [PATCH 34/42] root be it --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3f54f4e6a0..4cee5a8357 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -33,8 +33,8 @@ pipeline { docker { // image 'masstroy/alpine-docker-java-maven' image 'maven:3-alpine' - args '-v maven-cache:$HOME/.m2 \ - -v sonar-cache:$HOME/.sonar/cache' + args '-v maven-cache:$root/.m2 \ + -v sonar-cache:$root/.sonar/cache' } } options { @@ -54,7 +54,7 @@ pipeline { // script { // fetch master from origin so sonar scanner comparison works // sh "git fetch --no-tags ${GIT_URL} +refs/heads/master:refs/remotes/origin/master" - sh "${mvnCmdLine} -Duser.home=$HOME" + sh "${mvnCmdLine}" // sh 'mvn clean package sonar:sonar' // } } From 78752e5776a1edefe003e87be8978e04aaef0270 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Wed, 22 Apr 2020 18:16:13 +0200 Subject: [PATCH 35/42] root be it 2 --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4cee5a8357..196d1681b8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -33,8 +33,8 @@ pipeline { docker { // image 'masstroy/alpine-docker-java-maven' image 'maven:3-alpine' - args '-v maven-cache:$root/.m2 \ - -v sonar-cache:$root/.sonar/cache' + args '-v maven-cache:/root/.m2 \ + -v sonar-cache:/root/.sonar/cache' } } options { From f6f69d70c7e33471fcaa998b68bc118aa27c81ac Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource Date: Thu, 23 Apr 2020 11:14:18 +0200 Subject: [PATCH 36/42] remove git url not found anymore in SCM step --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 196d1681b8..6a60e31c66 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -43,9 +43,9 @@ pipeline { stages { stage('SCM') { steps { - // git 'https://github.com/sylvain-combe-sonarsource/simple-java-maven-app.git' + // git 'https://github.com/sylvain-combe-sonarsource/simple-java-maven-app.git' // sh "git fetch --no-tags ${GIT_URL} +refs/heads/master:refs/remotes/origin/master" - sh "echo ${GIT_URL}" + sh "echo toto" } } stage('Build') { From 60718d666b087acf0597f8c7859ab28dc9a496d5 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource <59280694+sylvain-combe-sonarsource@users.noreply.github.com> Date: Tue, 16 Mar 2021 14:17:54 +0100 Subject: [PATCH 37/42] Create azure-pipelines.yml --- azure-pipelines.yml | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 azure-pipelines.yml diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000000..354de984a5 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,41 @@ +# Maven +# Build your Java project and run tests with Apache Maven. +# Add steps that analyze code, save build artifacts, deploy, and more: +# https://docs.microsoft.com/azure/devops/pipelines/languages/java + +trigger: +- master + +pool: + vmImage: ubuntu-latest + +steps: +- task: SonarQubePrepare@4 + inputs: + SonarQube: 'SYCO' + scannerMode: 'Other' + extraProperties: | + # Additional properties that will be passed to the scanner, + # Put one key=value per line, example: + # sonar.exclusions=**/*.bin + sonar.projectKey=Azure-CI-Github-ALM + sonar.projectName=Azure-CI-Github-ALM +- task: Maven@3 + inputs: + mavenPomFile: 'pom.xml' + mavenOptions: '-Xmx1024m' + javaHomeOption: 'JDKVersion' + jdkVersionOption: '1.11' + jdkArchitectureOption: 'x64' + publishJUnitResults: true + testResultsFiles: '**/surefire-reports/TEST-*.xml' + goals: 'clean package sonar:sonar' +- task: PowerShell@2 + inputs: + targetType: 'inline' + script: | + # Write your PowerShell commands here. + Start-Sleep -Seconds 10 +- task: SonarQubePublish@4 + inputs: + pollingTimeoutSec: '300' From 2f9ffa20e3e9907e73f590325b3489dddc88760e Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource <59280694+sylvain-combe-sonarsource@users.noreply.github.com> Date: Tue, 16 Mar 2021 14:30:32 +0100 Subject: [PATCH 38/42] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 354de984a5..c8484e9213 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -5,6 +5,9 @@ trigger: - master +pr: +- master +- releases/* pool: vmImage: ubuntu-latest From bfb1408d950326f6b9c3ab66965eef5c4fa4bdd0 Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource <59280694+sylvain-combe-sonarsource@users.noreply.github.com> Date: Tue, 16 Mar 2021 17:17:32 +0100 Subject: [PATCH 39/42] Update App.java --- src/main/java/com/mycompany/app/App.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/mycompany/app/App.java b/src/main/java/com/mycompany/app/App.java index a79fe4567b..cb672e6a44 100644 --- a/src/main/java/com/mycompany/app/App.java +++ b/src/main/java/com/mycompany/app/App.java @@ -23,6 +23,7 @@ public static void main(String[] args) { } catch (InterruptedException e) { e.printStackTrace(); } + System.out.println("The end"); } private final String getMessage(boolean isSync) throws InterruptedException { From e0a3df75488f4b14093ccb3c78d21147981c538e Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource <59280694+sylvain-combe-sonarsource@users.noreply.github.com> Date: Tue, 16 Mar 2021 17:21:08 +0100 Subject: [PATCH 40/42] Update azure-pipelines.yml --- azure-pipelines.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index c8484e9213..6b4dc5822d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -4,10 +4,9 @@ # https://docs.microsoft.com/azure/devops/pipelines/languages/java trigger: -- master +- * pr: -- master -- releases/* +- * pool: vmImage: ubuntu-latest From 35de2e369fa55378ed5df0e44442e01f77c035eb Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource <59280694+sylvain-combe-sonarsource@users.noreply.github.com> Date: Tue, 16 Mar 2021 17:23:12 +0100 Subject: [PATCH 41/42] Update azure-pipelines.yml --- azure-pipelines.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 6b4dc5822d..9e73205d1a 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -4,9 +4,13 @@ # https://docs.microsoft.com/azure/devops/pipelines/languages/java trigger: -- * +- master +- branch* +- feature* pr: -- * +- master +- br* +- feature* pool: vmImage: ubuntu-latest From 77963860e3d186e024b7944cd3bc966cc36440ce Mon Sep 17 00:00:00 2001 From: sylvain-combe-sonarsource <59280694+sylvain-combe-sonarsource@users.noreply.github.com> Date: Tue, 16 Mar 2021 17:25:21 +0100 Subject: [PATCH 42/42] Update App.java --- src/main/java/com/mycompany/app/App.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/mycompany/app/App.java b/src/main/java/com/mycompany/app/App.java index cb672e6a44..a79fe4567b 100644 --- a/src/main/java/com/mycompany/app/App.java +++ b/src/main/java/com/mycompany/app/App.java @@ -23,7 +23,6 @@ public static void main(String[] args) { } catch (InterruptedException e) { e.printStackTrace(); } - System.out.println("The end"); } private final String getMessage(boolean isSync) throws InterruptedException {