From 7eb9cf74abe331b4f7302ed88e77d675b371b473 Mon Sep 17 00:00:00 2001 From: Ray Zhou Date: Thu, 7 Nov 2019 14:54:20 +0800 Subject: [PATCH 1/5] Update ids --- Jenkinsfile-online | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile-online b/Jenkinsfile-online index 67c8a7f20..6e5caa7b6 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -10,14 +10,14 @@ pipeline { } environment { - DOCKER_CREDENTIAL_ID = 'dockerhub-id' - GITHUB_CREDENTIAL_ID = 'github-id' - KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig' + DOCKER_CREDENTIAL_ID = 'ray-docker-hub-id' + GITHUB_CREDENTIAL_ID = 'ray-github-id' + KUBECONFIG_CREDENTIAL_ID = 'ks-config' REGISTRY = 'docker.io' - DOCKERHUB_NAMESPACE = 'docker_username' - GITHUB_ACCOUNT = 'kubesphere' - APP_NAME = 'devops-java-sample' - SONAR_CREDENTIAL_ID= 'sonar-token' + DOCKERHUB_NAMESPACE = 'rayzhou' + GITHUB_ACCOUNT = 'rayzhou2017' + APP_NAME = 'ray-devops-java-sample' + SONAR_CREDENTIAL_ID= 'sonar-token } stages { From ecd45148c2298b3a6f4e7d7b5191aaa234252dcd Mon Sep 17 00:00:00 2001 From: Ray Zhou Date: Thu, 7 Nov 2019 15:00:02 +0800 Subject: [PATCH 2/5] fix id typo --- Jenkinsfile-online | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile-online b/Jenkinsfile-online index 6e5caa7b6..51d3ba3d1 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -17,7 +17,7 @@ pipeline { DOCKERHUB_NAMESPACE = 'rayzhou' GITHUB_ACCOUNT = 'rayzhou2017' APP_NAME = 'ray-devops-java-sample' - SONAR_CREDENTIAL_ID= 'sonar-token + SONAR_CREDENTIAL_ID= 'sonar-token' } stages { From ca5c9d0b38bf145fdd60a35de6c4d24f7c0067f0 Mon Sep 17 00:00:00 2001 From: Ray Zhou Date: Wed, 5 Aug 2020 12:11:30 +0800 Subject: [PATCH 3/5] Add no sq in the Jenkinsfile Signed-off-by: Ray Zhou --- Jenkinsfile-online | 16 ------ Jenkinsfile-online-sq | 119 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 16 deletions(-) create mode 100644 Jenkinsfile-online-sq diff --git a/Jenkinsfile-online b/Jenkinsfile-online index 51d3ba3d1..9f6ce9953 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -17,7 +17,6 @@ pipeline { DOCKERHUB_NAMESPACE = 'rayzhou' GITHUB_ACCOUNT = 'rayzhou2017' APP_NAME = 'ray-devops-java-sample' - SONAR_CREDENTIAL_ID= 'sonar-token' } stages { @@ -35,21 +34,6 @@ pipeline { } } - 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.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN" - } - } - timeout(time: 1, unit: 'HOURS') { - waitForQualityGate abortPipeline: true - } - } - } - } - stage ('build & push') { steps { container ('maven') { diff --git a/Jenkinsfile-online-sq b/Jenkinsfile-online-sq new file mode 100644 index 000000000..51d3ba3d1 --- /dev/null +++ b/Jenkinsfile-online-sq @@ -0,0 +1,119 @@ +pipeline { + agent { + node { + label 'maven' + } + } + + parameters { + string(name:'TAG_NAME',defaultValue: '',description:'') + } + + environment { + DOCKER_CREDENTIAL_ID = 'ray-docker-hub-id' + GITHUB_CREDENTIAL_ID = 'ray-github-id' + KUBECONFIG_CREDENTIAL_ID = 'ks-config' + REGISTRY = 'docker.io' + DOCKERHUB_NAMESPACE = 'rayzhou' + GITHUB_ACCOUNT = 'rayzhou2017' + APP_NAME = 'ray-devops-java-sample' + SONAR_CREDENTIAL_ID= 'sonar-token' + } + + stages { + stage ('checkout scm') { + steps { + checkout(scm) + } + } + + stage ('unit test') { + steps { + container ('maven') { + 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.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 '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' + } + 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.*/ + } + } + 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{ + return params.TAG_NAME =~ /v.*/ + } + } + steps { + input(id: 'deploy-to-production', message: 'deploy to production?') + kubernetesDeploy(configs: 'deploy/prod-ol/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID") + } + } + } +} From fac774fca2932a14f2dd8227756502eea739b131 Mon Sep 17 00:00:00 2001 From: Ray Zhou Date: Wed, 19 Aug 2020 16:25:17 +0800 Subject: [PATCH 4/5] Test commit --- src/main/java/io/kubesphere/devops/HelloWorldController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/kubesphere/devops/HelloWorldController.java b/src/main/java/io/kubesphere/devops/HelloWorldController.java index a6bdd4cde..faf471e0d 100644 --- a/src/main/java/io/kubesphere/devops/HelloWorldController.java +++ b/src/main/java/io/kubesphere/devops/HelloWorldController.java @@ -14,6 +14,6 @@ public class HelloWorldController { @RequestMapping("/") public String sayHello() { - return "Really appreaciate your star, that's the power of our life."; + return "Hi! Really appreaciate your star, that's the power of our life."; } } From 25313be30bd2016c4754675108fb21094bd45035 Mon Sep 17 00:00:00 2001 From: Ray Zhou Date: Wed, 19 Aug 2020 16:30:48 +0800 Subject: [PATCH 5/5] Fix test --- .../java/io/kubesphere/devops/HelloWorldControllerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/kubesphere/devops/HelloWorldControllerTest.java b/src/test/java/io/kubesphere/devops/HelloWorldControllerTest.java index a83b15b54..5ec92d9e2 100644 --- a/src/test/java/io/kubesphere/devops/HelloWorldControllerTest.java +++ b/src/test/java/io/kubesphere/devops/HelloWorldControllerTest.java @@ -8,6 +8,6 @@ public class HelloWorldControllerTest { @Test public void testSayHello() { - assertEquals("Really appreaciate your star, that's the power of our life.", new HelloWorldController().sayHello()); + assertEquals("Hi! Really appreaciate your star, that's the power of our life.", new HelloWorldController().sayHello()); } }