@@ -17,6 +17,7 @@ pipeline {
1717 DOCKERHUB_NAMESPACE = 'zhangyalan'
1818 GITHUB_ACCOUNT = 'MaxLanGod'
1919 APP_NAME = 'devops-java-sample'
20+ SONAR_CREDENTIAL_ID = 'sonar-qube'
2021 }
2122
2223 stages {
@@ -29,16 +30,31 @@ pipeline {
2930 stage ('unit test') {
3031 steps {
3132 container ('maven') {
32- sh 'mvn clean -gs `pwd`/configuration/settings.xml test'
33+ sh 'mvn clean -o -gs `pwd`/configuration/settings.xml test'
3334 }
3435 }
3536 }
36-
37+
38+ stage('sonarqube analysis') {
39+ steps {
40+ container ('maven') {
41+ withCredentials([string(credentialsId: "$SONAR_CREDENTIAL_ID", variable: 'SONAR_TOKEN')]) {
42+ withSonarQubeEnv('sonar') {
43+ sh "mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.login=$SONAR_TOKEN"
44+ }
45+ }
46+ timeout(time: 1, unit: 'HOURS') {
47+ waitForQualityGate abortPipeline: true
48+ }
49+ }
50+ }
51+ }
52+
3753 stage ('build & push') {
3854 steps {
3955 container ('maven') {
40- sh 'mvn -Dmaven.test.skip=true -gs `pwd`/configuration/settings.xml clean package'
41- sh 'docker build -f Dockerfile-online -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .'
56+ sh 'mvn -o -Dmaven.test.skip=true -gs `pwd`/configuration/settings.xml clean package'
57+ sh 'docker build --no-cache - f Dockerfile-online -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .'
4258 withCredentials([usernamePassword(passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,credentialsId : "$DOCKER_CREDENTIAL_ID" ,)]) {
4359 sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin'
4460 sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER'
@@ -49,7 +65,7 @@ pipeline {
4965
5066 stage('push latest'){
5167 when{
52- branch 'master '
68+ branch 'sonarqube '
5369 }
5470 steps{
5571 container ('maven') {
@@ -61,7 +77,7 @@ pipeline {
6177
6278 stage('deploy to dev') {
6379 when{
64- branch 'master '
80+ branch 'sonarqube '
6581 }
6682 steps {
6783 input(id: 'deploy-to-dev', message: 'deploy to dev?')
0 commit comments