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:latest .'
|
}
|
}
|
}
|
|
stage('镜像推送') {
|
agent none
|
steps {
|
container('maven') {
|
withCredentials([usernamePassword(credentialsId : 'aliyun' ,passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,)]) {
|
sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin'
|
sh 'docker tag zhbaw:latest $REGISTRY/$DOCKERHUB_NAMESPACE/zhbaw:SNAPSHOT-$BUILD_NUMBER'
|
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/zhbaw:SNAPSHOT-$BUILD_NUMBER'
|
sh 'docker rmi $REGISTRY/$DOCKERHUB_NAMESPACE/zhbaw:SNAPSHOT-$BUILD_NUMBER'
|
sh 'docker rmi zhbaw:latest'
|
}
|
}
|
|
}
|
}
|
|
stage('deploy to dev') {
|
agent none
|
steps {
|
container('maven') {
|
withCredentials([kubeconfigContent(credentialsId : 'kube-zhba' ,variable : 'KUBE_VAR' ,)]) {
|
sh 'kubectl apply -f deploy/deploy.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 = 'registry.cn-hangzhou.aliyuncs.com'
|
DOCKERHUB_NAMESPACE = 'arsn'
|
GITHUB_ACCOUNT = 'kubesphere'
|
APP_NAME = 'devops-java-sample'
|
}
|
parameters {
|
string(name: 'TAG_NAME', defaultValue: '', description: '')
|
}
|
}
|