diff --git a/Jenkinsfile-on-prem b/Jenkinsfile-on-prem index b76a9ccb..1b3877f5 100644 --- a/Jenkinsfile-on-prem +++ b/Jenkinsfile-on-prem @@ -10,13 +10,14 @@ pipeline { } environment { - HARBOR_CREDENTIAL_ID = 'harbor-id' - GITLAB_CREDENTIAL_ID = 'gitlab-id' + DOCKER_CREDENTIAL_ID = 'dockerhub-id' + GITHUB_CREDENTIAL_ID = 'Github-id' KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig' - REGISTRY = 'harbor.devops.kubesphere.local:30280' - HARBOR_NAMESPACE = 'library' - GITLAB_ACCOUNT = 'admin1' + REGISTRY = 'docker.io' + DOCKERHUB_NAMESPACE = 'yeha' + GITHUB_ACCOUNT = 'yeha49' APP_NAME = 'devops-java-sample' + SONAR_CREDENTIAL_ID = 'sonar-qube' } stages { @@ -29,15 +30,30 @@ 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' } } } + + stage('sonarqube analysis') { + steps { + container ('maven') { + withCredentials([string(credentialsId: "$SONAR_CREDENTIAL_ID", variable: 'SONAR_TOKEN')]) { + withSonarQubeEnv('sonar') { + sh "mvn sonar:sonar -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN" + } + } + timeout(time: 1, unit: 'HOURS') { + waitForQualityGate abortPipeline: true + } + } + } + } 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 -f Dockerfile-on-prem -t $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .' withCredentials([usernamePassword(passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,credentialsId : "$HARBOR_CREDENTIAL_ID" ,)]) { sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin' diff --git a/Jenkinsfile-online b/Jenkinsfile-online index 2ca69e7f..5bc707a1 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -11,12 +11,13 @@ pipeline { environment { DOCKER_CREDENTIAL_ID = 'dockerhub-id' - GITHUB_CREDENTIAL_ID = 'github-id' + GITHUB_CREDENTIAL_ID = 'Github-id' KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig' REGISTRY = 'docker.io' - DOCKERHUB_NAMESPACE = 'docker_username' - GITHUB_ACCOUNT = 'kubesphere' + DOCKERHUB_NAMESPACE = 'yeha' + GITHUB_ACCOUNT = 'yeha49' APP_NAME = 'devops-java-sample' + SONAR_CREDENTIAL_ID = 'sonar-aaa' } stages { @@ -33,6 +34,21 @@ pipeline { } } } + + stage('sonarqube analysis') { + steps { + container ('maven') { + withCredentials([string(credentialsId: "$SONAR_CREDENTIAL_ID", variable: 'SONAR_TOKEN')]) { + withSonarQubeEnv('sonar') { + sh "mvn sonar:sonar -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN" + } + } + timeout(time: 1, unit: 'HOURS') { + waitForQualityGate abortPipeline: true + } + } + } + } stage ('build & push') { steps { diff --git a/pom.xml b/pom.xml index 2b912c1c..daba986d 100644 --- a/pom.xml +++ b/pom.xml @@ -25,31 +25,7 @@ spring-boot-starter-parent 2.1.11.RELEASE - - - - spring - https://maven.aliyun.com/repository/spring - - true - - - true - - - - - - spring - https://maven.aliyun.com/repository/spring - - true - - - true - - - +