| New file |
| | |
| | | pipeline { |
| | | agent { |
| | | node { |
| | | label 'maven' |
| | | } |
| | | |
| | | } |
| | | stages { |
| | | stage('拉取代码') { |
| | | agent none |
| | | steps { |
| | | container('base') { |
| | | git(url: 'http://192.168.0.105:10010/r/zhba_management_w.git', credentialsId: 'gitblit', branch: 'master', changelog: true, poll: false) |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | stage('打 jar 包') { |
| | | agent none |
| | | steps { |
| | | container('maven') { |
| | | sh 'ls' |
| | | sh 'mvn clean package -Dmaven.test.skip=true' |
| | | sh 'ls target/' |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | stage('镜像打包') { |
| | | agent none |
| | | steps { |
| | | container('maven') { |
| | | sh 'docker build -f Dockerfile -t zhbaw-harbor:latest .' |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | stage('镜像推送') { |
| | | agent none |
| | | steps { |
| | | container('maven') { |
| | | withCredentials([usernamePassword(credentialsId : 'harbor' ,passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,)]) { |
| | | sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin' |
| | | sh 'docker tag zhbaw-harbor:latest $REGISTRY/$DOCKERHUB_NAMESPACE/zhbaw-harbor:SNAPSHOT-$BUILD_NUMBER' |
| | | sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/zhbaw-harbor:SNAPSHOT-$BUILD_NUMBER' |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | stage('deploy to dev') { |
| | | agent none |
| | | steps { |
| | | container('maven') { |
| | | withCredentials([kubeconfigContent(credentialsId : 'kube-zhba' ,variable : 'KUBE_VAR' ,)]) { |
| | | sh 'kubectl apply -f deploy/deploy-harbor.yml' |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | stage('deploy to production') { |
| | | steps { |
| | | input(id: 'deploy-to-production', message: 'deploy to production?') |
| | | kubernetesDeploy(configs: 'deploy/prod-ol/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID") |
| | | } |
| | | } |
| | | |
| | | } |
| | | environment { |
| | | DOCKER_CREDENTIAL_ID = 'dockerhub-id' |
| | | GITHUB_CREDENTIAL_ID = 'github-id' |
| | | KUBECONFIG_CREDENTIAL_ID = 'kube-zhba' |
| | | REGISTRY = '192.168.0.191' |
| | | DOCKERHUB_NAMESPACE = 'zhbaw' |
| | | GITHUB_ACCOUNT = 'kubesphere' |
| | | APP_NAME = 'devops-java-sample' |
| | | } |
| | | parameters { |
| | | string(name: 'TAG_NAME', defaultValue: '', description: '') |
| | | } |
| | | } |