From 52d83497ee5512ca2e1255a2d32bed6d8b2f9c83 Mon Sep 17 00:00:00 2001 From: Derek Sharpe Date: Thu, 17 Mar 2022 15:57:31 -0500 Subject: [PATCH 01/15] added Sonar step to Jenkinsfile --- Jenkinsfile | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 9d9ca08767..3bb9b00b74 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -75,7 +75,20 @@ pipeline { } } } - stage ('Alias Test') { + stage ('Analyze') { + when { + anyOf { + changeRequest() + branch "main" + } + } + steps { + withCredentials([string(credentialsId: 'ecnj_sonar_token', variable: 'SONAR_TOKEN')]) { + sh '-B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=oracle_weblogic-deploy-tooling' + } + } + } + stage ('Alias Test') { // only run this stage when triggered by a cron timer and the commit does not have []skip-ci in the message // for example, only run integration tests during the timer triggered nightly build when { @@ -129,6 +142,5 @@ pipeline { ''' } } - } } From 567498fed4c27eb9f36c18039955fba4abb23e34 Mon Sep 17 00:00:00 2001 From: Derek Sharpe Date: Fri, 18 Mar 2022 10:32:08 -0500 Subject: [PATCH 02/15] print all environment variables during the environment stage --- Jenkinsfile | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3bb9b00b74..37580ee1fe 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,12 +13,7 @@ pipeline { jdk 'jdk8' } steps { - sh ''' - echo "PATH = ${PATH}" - echo "JAVA_HOME = ${JAVA_HOME}" - echo "M2_HOME = ${M2_HOME}" - mvn --version - ''' + sh 'env|sort' } } stage ('Build') { @@ -82,9 +77,13 @@ pipeline { branch "main" } } + tools { + maven 'maven-3.6.0' + jdk 'jdk11' + } steps { withCredentials([string(credentialsId: 'ecnj_sonar_token', variable: 'SONAR_TOKEN')]) { - sh '-B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=oracle_weblogic-deploy-tooling' + sh 'mvn -B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=oracle_weblogic-deploy-tooling' } } } From 60db58e639dcd6c0060f74bd2cd27be51cc06d8b Mon Sep 17 00:00:00 2001 From: Derek Sharpe Date: Fri, 18 Mar 2022 10:35:00 -0500 Subject: [PATCH 03/15] removed GitHub build action (moved Sonar step to Jenkinsfile) --- .github/workflows/build.yml | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index f668817031..0000000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Build -on: - push: - branches: - - main - pull_request: - types: [opened, synchronize, reopened] -jobs: - build: - name: Build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - java-version: 11 - - name: Cache SonarCloud packages - uses: actions/cache@v1 - with: - path: ~/.sonar/cache - key: ${{ runner.os }}-sonar - restore-keys: ${{ runner.os }}-sonar - - name: Cache Maven packages - uses: actions/cache@v1 - with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 - - name: Build and analyze - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=oracle_weblogic-deploy-tooling From 5c633ff08dc71ace0d48d68fe34a6bb4f3cb9db2 Mon Sep 17 00:00:00 2001 From: Derek Sharpe Date: Fri, 18 Mar 2022 13:35:49 -0500 Subject: [PATCH 04/15] Jenkins Branch Source plugin not working, adding sonar branch name to command line --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 37580ee1fe..b5f3b3594a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -83,7 +83,7 @@ pipeline { } steps { withCredentials([string(credentialsId: 'ecnj_sonar_token', variable: 'SONAR_TOKEN')]) { - sh 'mvn -B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=oracle_weblogic-deploy-tooling' + sh 'mvn -B sonar:sonar -Dsonar.projectKey=oracle_weblogic-deploy-tooling -Dsonar.branch.name=${GIT_BRANCH}' } } } From 285c89584e689fec04d9698896b1460a05fec44f Mon Sep 17 00:00:00 2001 From: Derek Sharpe Date: Fri, 18 Mar 2022 19:26:13 -0500 Subject: [PATCH 05/15] trying with SonarQubeEnv --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b5f3b3594a..997c7458cd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -82,8 +82,8 @@ pipeline { jdk 'jdk11' } steps { - withCredentials([string(credentialsId: 'ecnj_sonar_token', variable: 'SONAR_TOKEN')]) { - sh 'mvn -B sonar:sonar -Dsonar.projectKey=oracle_weblogic-deploy-tooling -Dsonar.branch.name=${GIT_BRANCH}' + withSonarQubeEnv(credentialsId: 'ecnj_sonar_token') { + sh 'mvn -B sonar:sonar -Dsonar.projectKey=oracle_weblogic-deploy-tooling' } } } From ad19a18d5cc373c0de92f8f5b778275ff3dfec97 Mon Sep 17 00:00:00 2001 From: Derek Sharpe Date: Fri, 18 Mar 2022 19:30:23 -0500 Subject: [PATCH 06/15] trying with SonarQubeEnv --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 997c7458cd..ecde3d5d70 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -82,7 +82,7 @@ pipeline { jdk 'jdk11' } steps { - withSonarQubeEnv(credentialsId: 'ecnj_sonar_token') { + withSonarQubeEnv('sonarqube-scanner', credentialsId: 'ecnj_sonar_token') { sh 'mvn -B sonar:sonar -Dsonar.projectKey=oracle_weblogic-deploy-tooling' } } From 54e811646c9901500f8128928dc6de17d2566f74 Mon Sep 17 00:00:00 2001 From: Derek Sharpe Date: Fri, 18 Mar 2022 19:38:48 -0500 Subject: [PATCH 07/15] trying with SonarQubeEnv --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index ecde3d5d70..6b1237df6c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -82,7 +82,7 @@ pipeline { jdk 'jdk11' } steps { - withSonarQubeEnv('sonarqube-scanner', credentialsId: 'ecnj_sonar_token') { + withSonarQubeEnv('SonarCloud') { sh 'mvn -B sonar:sonar -Dsonar.projectKey=oracle_weblogic-deploy-tooling' } } From 7f318ff3ac0a99e61dc046311aafa0415df3150d Mon Sep 17 00:00:00 2001 From: Derek Sharpe Date: Mon, 21 Mar 2022 10:42:09 -0500 Subject: [PATCH 08/15] all Jenkinsfile executions of mvn should be in batch mode --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6b1237df6c..18a874badc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -37,7 +37,7 @@ pipeline { } } steps { - sh 'mvn -Dunit-test-wlst-dir=${WLST_DIR} test' + sh 'mvn -B -Dunit-test-wlst-dir=${WLST_DIR} test' } post { always { @@ -62,7 +62,7 @@ pipeline { } } steps { - sh 'mvn -DskipITs=false -Dmw_home=${ORACLE_HOME} -Ddb.use.container.network=true verify' + sh 'mvn -B -DskipITs=false -Dmw_home=${ORACLE_HOME} -Ddb.use.container.network=true verify' } post { always { From 44e5d6f698b593fb512c167c1e76df89082a7c10 Mon Sep 17 00:00:00 2001 From: Derek Sharpe Date: Mon, 21 Mar 2022 12:49:20 -0500 Subject: [PATCH 09/15] added GITHUB token for PR decoration --- Jenkinsfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 18a874badc..48bda4d182 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -83,7 +83,9 @@ pipeline { } steps { withSonarQubeEnv('SonarCloud') { - sh 'mvn -B sonar:sonar -Dsonar.projectKey=oracle_weblogic-deploy-tooling' + withCredentials([string(credentialsId: 'encj_github_token', variable: 'GITHUB_TOKEN')]) { + sh 'mvn -B sonar:sonar -Dsonar.projectKey=oracle_weblogic-deploy-tooling' + } } } } From 7f84c410f949c5462f5eac9c57c97acc185af79e Mon Sep 17 00:00:00 2001 From: Derek Sharpe Date: Mon, 21 Mar 2022 13:11:25 -0500 Subject: [PATCH 10/15] replaced deprecated path for test exclusion and added python version declaration --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8174a79be2..45fb6b817e 100644 --- a/pom.xml +++ b/pom.xml @@ -51,8 +51,9 @@ https://sonarcloud.io src/main 7 + 2 .flattened-pom.xml,target/** - src/test/** + core/src/test/** ${env.WLST_DIR} true true From ffc0d7152895923d4e7974de0a16b78004fa2818 Mon Sep 17 00:00:00 2001 From: Derek Sharpe Date: Mon, 21 Mar 2022 14:41:07 -0500 Subject: [PATCH 11/15] fix code coverage for basic unit tests using Jacoco --- core/pom.xml | 8 ++++---- pom.xml | 20 +++++--------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 5ddc75ccc2..f54136cf62 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -88,6 +88,10 @@ + + org.jacoco + jacoco-maven-plugin + org.apache.maven.plugins maven-jar-plugin @@ -163,10 +167,6 @@ org.codehaus.mojo flatten-maven-plugin - - org.jacoco - jacoco-maven-plugin - diff --git a/pom.xml b/pom.xml index 45fb6b817e..4b6c34a46e 100644 --- a/pom.xml +++ b/pom.xml @@ -54,6 +54,8 @@ 2 .flattened-pom.xml,target/** core/src/test/** + core/target/site/jacoco/jacoco.xml + ${env.WLST_DIR} true true @@ -153,10 +155,6 @@ org.apache.maven.plugins maven-surefire-plugin 3.0.0-M5 - - - ${surefireArgLine} - io.rhpatrick.mojo @@ -184,25 +182,17 @@ 0.8.7 - pre-unit-test + prepare-agent prepare-agent - - ${sonar.jacoco.reportPath} - surefireArgLine - - post-unit-test - site + report + post-integration-test report - - ${project.reporting.outputDirectory}/jacoco-ut - ${sonar.jacoco.reportPath} - From add33b9918f8d4b01ae7db19891163ba7c4d4b07 Mon Sep 17 00:00:00 2001 From: Derek Sharpe Date: Tue, 22 Mar 2022 12:33:49 -0500 Subject: [PATCH 12/15] use groovy to alter sonar command line properties based on changeRequest --- Jenkinsfile | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 48bda4d182..7abeca3bef 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -84,7 +84,7 @@ pipeline { steps { withSonarQubeEnv('SonarCloud') { withCredentials([string(credentialsId: 'encj_github_token', variable: 'GITHUB_TOKEN')]) { - sh 'mvn -B sonar:sonar -Dsonar.projectKey=oracle_weblogic-deploy-tooling' + runSonarScanner() } } } @@ -145,3 +145,21 @@ pipeline { } } } + +void runSonarScanner() { + if (changeRequest()) { + def changeUrl = env.CHANGE_URL.split("/") + def org = changeUrl[3] + def repo = changeUrl[4] + sh 'mvn -B sonar:sonar \ + -Dsonar.projectKey=oracle_weblogic-deploy-tooling \ + -Dsonar.pullrequest.provider=GitHub \ + -Dsonar.pullrequest.github.repository=${org}/${repo} \ + -Dsonar.pullrequest.key=${env.CHANGE_ID} \ + -Dsonar.pullrequest.branch=${env.CHANGE_BRANCH}' + } else { + sh 'mvn -B sonar:sonar \ + -Dsonar.projectKey=oracle_weblogic-deploy-tooling \ + -Dsonar.pullrequest.branch=${env.CHANGE_BRANCH}' + } +} From 08a092547a3339b757ed1808591a890af6a2bc5b Mon Sep 17 00:00:00 2001 From: Derek Sharpe Date: Tue, 22 Mar 2022 12:48:26 -0500 Subject: [PATCH 13/15] correct copy and paste error for non-change request sonar --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7abeca3bef..e391eecdb4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -160,6 +160,6 @@ void runSonarScanner() { } else { sh 'mvn -B sonar:sonar \ -Dsonar.projectKey=oracle_weblogic-deploy-tooling \ - -Dsonar.pullrequest.branch=${env.CHANGE_BRANCH}' + -Dsonar.branch.name=${env.BRANCH_NAME}' } } From 0e9725a3cff730eee946c388b271432c80adc7f5 Mon Sep 17 00:00:00 2001 From: Derek Sharpe Date: Tue, 22 Mar 2022 15:18:09 -0500 Subject: [PATCH 14/15] replace single quote with double quote in groovy method --- Jenkinsfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e391eecdb4..1471c4aae5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -151,15 +151,16 @@ void runSonarScanner() { def changeUrl = env.CHANGE_URL.split("/") def org = changeUrl[3] def repo = changeUrl[4] - sh 'mvn -B sonar:sonar \ + sh "mvn -B sonar:sonar \ -Dsonar.projectKey=oracle_weblogic-deploy-tooling \ -Dsonar.pullrequest.provider=GitHub \ -Dsonar.pullrequest.github.repository=${org}/${repo} \ -Dsonar.pullrequest.key=${env.CHANGE_ID} \ - -Dsonar.pullrequest.branch=${env.CHANGE_BRANCH}' + -Dsonar.pullrequest.branch=${env.CHANGE_BRANCH} \ + -Dsonar.pullrequest.base=${env.CHANGE_TARGET}" } else { - sh 'mvn -B sonar:sonar \ + sh "mvn -B sonar:sonar \ -Dsonar.projectKey=oracle_weblogic-deploy-tooling \ - -Dsonar.branch.name=${env.BRANCH_NAME}' + -Dsonar.branch.name=${env.BRANCH_NAME}" } } From 86d264c1265a138a65de7d44ff63b7fffe21af3a Mon Sep 17 00:00:00 2001 From: Derek Sharpe Date: Tue, 22 Mar 2022 15:47:58 -0500 Subject: [PATCH 15/15] removed hardcoded project name --- Jenkinsfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1471c4aae5..8023607e83 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -147,12 +147,12 @@ pipeline { } void runSonarScanner() { + def changeUrl = env.CHANGE_URL.split("/") + def org = changeUrl[3] + def repo = changeUrl[4] if (changeRequest()) { - def changeUrl = env.CHANGE_URL.split("/") - def org = changeUrl[3] - def repo = changeUrl[4] sh "mvn -B sonar:sonar \ - -Dsonar.projectKey=oracle_weblogic-deploy-tooling \ + -Dsonar.projectKey=${org}_${repo} \ -Dsonar.pullrequest.provider=GitHub \ -Dsonar.pullrequest.github.repository=${org}/${repo} \ -Dsonar.pullrequest.key=${env.CHANGE_ID} \ @@ -160,7 +160,7 @@ void runSonarScanner() { -Dsonar.pullrequest.base=${env.CHANGE_TARGET}" } else { sh "mvn -B sonar:sonar \ - -Dsonar.projectKey=oracle_weblogic-deploy-tooling \ + -Dsonar.projectKey=${org}_${repo} \ -Dsonar.branch.name=${env.BRANCH_NAME}" } }