From 9aa194bd9bb3ede8133bb90057691b8212622719 Mon Sep 17 00:00:00 2001 From: moyuming <31557158+moyuming@users.noreply.github.com> Date: Mon, 7 Nov 2022 21:19:06 +0800 Subject: [PATCH 1/3] Update Jenkinsfile-online --- Jenkinsfile-online | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile-online b/Jenkinsfile-online index 2ca69e7f1..558526564 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -14,9 +14,10 @@ pipeline { GITHUB_CREDENTIAL_ID = 'github-id' KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig' REGISTRY = 'docker.io' - DOCKERHUB_NAMESPACE = 'docker_username' - GITHUB_ACCOUNT = 'kubesphere' + DOCKERHUB_NAMESPACE = 'moyumin' + GITHUB_ACCOUNT = 'moyumin' APP_NAME = 'devops-java-sample' + SONAR_CREDENTIAL_ID = 'sonar-qube' } stages { From a05a74adc5cdeef6552d707569ab77aec8b15a62 Mon Sep 17 00:00:00 2001 From: moyuming <31557158+moyuming@users.noreply.github.com> Date: Mon, 7 Nov 2022 21:41:48 +0800 Subject: [PATCH 2/3] Update Jenkinsfile-online --- Jenkinsfile-online | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile-online b/Jenkinsfile-online index 558526564..923221b26 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -30,16 +30,31 @@ pipeline { stage ('unit test') { steps { container ('maven') { - sh 'mvn clean -gs `pwd`/configuration/settings.xml test' + sh 'mvn clean -o -gs `pwd`/configuration/settings.xml test' } } } - + + stage('sonarqube analysis') { + steps { + container ('maven') { + withCredentials([string(credentialsId: "$SONAR_CREDENTIAL_ID", variable: 'SONAR_TOKEN')]) { + withSonarQubeEnv('sonar') { + sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.login=$SONAR_TOKEN" + } + } + timeout(time: 1, unit: 'HOURS') { + waitForQualityGate abortPipeline: true + } + } + } + } + stage ('build & push') { steps { container ('maven') { - sh 'mvn -Dmaven.test.skip=true -gs `pwd`/configuration/settings.xml clean package' - sh 'docker build -f Dockerfile-online -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .' + sh 'mvn -o -Dmaven.test.skip=true -gs `pwd`/configuration/settings.xml clean package' + sh 'docker build --no-cache -f Dockerfile-online -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .' withCredentials([usernamePassword(passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,credentialsId : "$DOCKER_CREDENTIAL_ID" ,)]) { sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin' sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER' @@ -50,7 +65,7 @@ pipeline { stage('push latest'){ when{ - branch 'master' + branch 'sonarqube' } steps{ container ('maven') { @@ -62,7 +77,7 @@ pipeline { stage('deploy to dev') { when{ - branch 'master' + branch 'sonarqube' } steps { input(id: 'deploy-to-dev', message: 'deploy to dev?') From 22b946f8433897dc6ce56ea5583cbd675ef34bcf Mon Sep 17 00:00:00 2001 From: moyuming <31557158+moyuming@users.noreply.github.com> Date: Mon, 7 Nov 2022 21:44:49 +0800 Subject: [PATCH 3/3] Update Jenkinsfile-online --- Jenkinsfile-online | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile-online b/Jenkinsfile-online index 923221b26..9185c0ae5 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -30,7 +30,7 @@ pipeline { stage ('unit test') { steps { container ('maven') { - sh 'mvn clean -o -gs `pwd`/configuration/settings.xml test' + sh 'mvn clean -gs `pwd`/configuration/settings.xml test' } } } @@ -40,7 +40,7 @@ pipeline { container ('maven') { withCredentials([string(credentialsId: "$SONAR_CREDENTIAL_ID", variable: 'SONAR_TOKEN')]) { withSonarQubeEnv('sonar') { - sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.login=$SONAR_TOKEN" + sh "mvn sonar:sonar -gs `pwd`/configuration/settings.xml -Dsonar.login=$SONAR_TOKEN" } } timeout(time: 1, unit: 'HOURS') { @@ -53,7 +53,7 @@ pipeline { stage ('build & push') { steps { container ('maven') { - sh 'mvn -o -Dmaven.test.skip=true -gs `pwd`/configuration/settings.xml clean package' + sh 'mvn -Dmaven.test.skip=true -gs `pwd`/configuration/settings.xml clean package' sh 'docker build --no-cache -f Dockerfile-online -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .' withCredentials([usernamePassword(passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,credentialsId : "$DOCKER_CREDENTIAL_ID" ,)]) { sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin'