diff --git a/Jenkinsfile-online b/Jenkinsfile-online index 2ca69e7f1..bc909e1f6 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -11,12 +11,13 @@ pipeline { environment { DOCKER_CREDENTIAL_ID = 'dockerhub-id' - GITHUB_CREDENTIAL_ID = 'github-id' - KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig' + GITHUB_CREDENTIAL_ID = 'git-hub' + KUBECONFIG_CREDENTIAL_ID = 'kubeconfig' REGISTRY = 'docker.io' - DOCKERHUB_NAMESPACE = 'docker_username' - GITHUB_ACCOUNT = 'kubesphere' + DOCKERHUB_NAMESPACE = 'jayang' + GITHUB_ACCOUNT = 'jayangyy' APP_NAME = 'devops-java-sample' + SONAR_CREDENTIAL_ID= 'sonar-token' } stages { @@ -33,61 +34,21 @@ pipeline { } } } - - 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 .' - 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' - } - } - } - } - - stage('push latest'){ - when{ - branch 'master' - } - steps{ - container ('maven') { - sh 'docker tag $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest ' - sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest ' - } - } - } - - stage('deploy to dev') { - when{ - branch 'master' - } + stage('sonarqube analysis') { steps { - input(id: 'deploy-to-dev', message: 'deploy to dev?') - kubernetesDeploy(configs: 'deploy/dev-ol/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID") - } - } - stage('push with tag'){ - when{ - expression{ - return params.TAG_NAME =~ /v.*/ + 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 + } } } - steps { - container ('maven') { - input(id: 'release-image-with-tag', message: 'release image with tag?') - withCredentials([usernamePassword(credentialsId: "$GITHUB_CREDENTIAL_ID", passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) { - sh 'git config --global user.email "kubesphere@yunify.com" ' - sh 'git config --global user.name "kubesphere" ' - sh 'git tag -a $TAG_NAME -m "$TAG_NAME" ' - sh 'git push http://$GIT_USERNAME:$GIT_PASSWORD@github.com/$GITHUB_ACCOUNT/devops-java-sample.git --tags --ipv4' - } - sh 'docker tag $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$TAG_NAME ' - sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$TAG_NAME ' - } - } } + stage('deploy to production') { when{ expression{ diff --git a/configuration/settings.xml b/configuration/settings.xml index 9838b7c97..f3b8cbb5f 100644 --- a/configuration/settings.xml +++ b/configuration/settings.xml @@ -11,7 +11,7 @@ jenkins - true + true diff --git a/pom.xml b/pom.xml index 2b912c1c1..776056f4d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,53 +1,51 @@ - - 4.0.0 + + 4.0.0 - io.kubesphere.devops - devops-sample - 0.0.1-SNAPSHOT - devops-sample :: HelloWorld Demo + io.kubesphere.devops + devops-sample + 0.0.1-SNAPSHOT + devops-sample :: HelloWorld Demo - - UTF-8 - UTF-8 + + UTF-8 + UTF-8 - - + - ${PWD}/./target/jacoco.exec - target/classes - + ${PWD}/./target/jacoco.exec + target/classes + + + + + org.springframework.boot + spring-boot-starter-parent + 1.4.1.BUILD-SNAPSHOT + - - - org.springframework.boot - spring-boot-starter-parent - 2.1.11.RELEASE - - - spring - https://maven.aliyun.com/repository/spring - - true - - - true - + spring-snapshots + http://repo.spring.io/snapshot + true + + + spring-milestones + http://repo.spring.io/milestone - spring - https://maven.aliyun.com/repository/spring - - true - - - true - + spring-snapshots + http://repo.spring.io/snapshot + + + spring-milestones + http://repo.spring.io/milestone @@ -59,7 +57,7 @@ junit junit - 4.13.1 + 4.12 @@ -70,28 +68,28 @@ jacoco-maven-plugin 0.8.2 - true + true - - agent-for-ut - - prepare-agent - - - - agent-for-it - - prepare-agent-integration - - - - jacoco-site - verify - - report - - + + agent-for-ut + + prepare-agent + + + + agent-for-it + + prepare-agent-integration + + + + jacoco-site + verify + + report + +