From 9c2e89f4f862b7ffe24b43c52345a5918ff8988d Mon Sep 17 00:00:00 2001 From: wangfei Date: Wed, 19 Apr 2023 10:11:34 +0800 Subject: [PATCH] format Dockerfile and Jenkinsfile --- Dockerfile-on-prem | 2 - Jenkinsfile-on-prem | 100 ++++++++++++++++++++++--------------------- Jenkinsfile-online | 102 ++++++++++++++++++++++---------------------- 3 files changed, 103 insertions(+), 101 deletions(-) diff --git a/Dockerfile-on-prem b/Dockerfile-on-prem index 69dc369..2bbb5e1 100644 --- a/Dockerfile-on-prem +++ b/Dockerfile-on-prem @@ -5,5 +5,3 @@ WORKDIR /home COPY target/*.jar /home ENTRYPOINT java -jar *.jar - - diff --git a/Jenkinsfile-on-prem b/Jenkinsfile-on-prem index b76a9cc..ef339a6 100644 --- a/Jenkinsfile-on-prem +++ b/Jenkinsfile-on-prem @@ -1,9 +1,9 @@ pipeline { - agent { - node { - label 'maven' + agent { + node { + label 'maven' + } } - } parameters { string(name:'TAG_NAME',defaultValue: '',description:'') @@ -20,23 +20,23 @@ pipeline { } stages { - stage ('checkout scm') { + stage('checkout scm') { steps { checkout(scm) } } - stage ('unit test') { + stage('unit test') { steps { - container ('maven') { + container('maven') { sh 'mvn clean -o -gs `pwd`/configuration/settings.xml test' } } } - stage ('build & push') { + stage('build & push') { steps { - container ('maven') { + container('maven') { sh 'mvn -o -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" ,)]) { @@ -47,57 +47,59 @@ pipeline { } } - stage('push latest'){ - when{ - branch 'master' - } - steps{ - container ('maven') { - sh 'docker tag $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:latest ' - sh 'docker push $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:latest ' + stage('push latest') { + when { + branch 'master' + } + steps { + container('maven') { + sh 'docker tag $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:latest ' + sh 'docker push $REGISTRY/$HARBOR_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/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID") - } + when { + branch 'master' + } + steps { + input(id: 'deploy-to-dev', message: 'deploy to dev?') + kubernetesDeploy(configs: 'deploy/dev/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID") + } } + stage('push with tag'){ - when{ - expression{ - return params.TAG_NAME =~ /v.*/ + when { + expression { + return params.TAG_NAME =~ /v.*/ + } + } + steps { + container('maven') { + input(id: 'release-image-with-tag', message: 'release image with tag?') + withCredentials([usernamePassword(credentialsId: "$GITLAB_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@gitlab.devops.kubesphere.local:30080/$GITLAB_ACCOUNT/devops-java-sample.git --tags --ipv4' + } + sh 'docker tag $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:$TAG_NAME ' + sh 'docker push $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:$TAG_NAME ' + } } - } - steps { - container ('maven') { - input(id: 'release-image-with-tag', message: 'release image with tag?') - withCredentials([usernamePassword(credentialsId: "$GITLAB_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@gitlab.devops.kubesphere.local:30080/$GITLAB_ACCOUNT/devops-java-sample.git --tags --ipv4' - } - sh 'docker tag $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:$TAG_NAME ' - sh 'docker push $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:$TAG_NAME ' - } - } } + stage('deploy to production') { - when{ - expression{ - return params.TAG_NAME =~ /v.*/ + when { + expression { + return params.TAG_NAME =~ /v.*/ + } + } + steps { + input(id: 'deploy-to-production', message: 'deploy to production?') + kubernetesDeploy(configs: 'deploy/prod/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID") } - } - steps { - input(id: 'deploy-to-production', message: 'deploy to production?') - kubernetesDeploy(configs: 'deploy/prod/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID") - } } } } diff --git a/Jenkinsfile-online b/Jenkinsfile-online index 2ca69e7..47f8eb9 100644 --- a/Jenkinsfile-online +++ b/Jenkinsfile-online @@ -1,9 +1,9 @@ pipeline { - agent { - node { - label 'maven' + agent { + node { + label 'maven' + } } - } parameters { string(name:'TAG_NAME',defaultValue: '',description:'') @@ -20,13 +20,13 @@ pipeline { } stages { - stage ('checkout scm') { + stage('checkout scm') { steps { checkout(scm) } } - stage ('unit test') { + stage('unit test') { steps { container ('maven') { sh 'mvn clean -gs `pwd`/configuration/settings.xml test' @@ -34,9 +34,9 @@ pipeline { } } - stage ('build & push') { + stage('build & push') { steps { - container ('maven') { + 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" ,)]) { @@ -47,57 +47,59 @@ pipeline { } } - 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('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") - } + 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.*/ + + 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 ' + } } - } - 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.*/ + 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") } - } - steps { - input(id: 'deploy-to-production', message: 'deploy to production?') - kubernetesDeploy(configs: 'deploy/prod-ol/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID") - } } } } -- Gitee