k8s流水线
1.添加参数化构建根据自己情况更改
流水线脚本
def label = "jnlp-slave"
def harbor_addr = "xxxx.com/xxxxx_cicd" //根据自己情况更改
def aliyunhub_auth = "5e29c51a-xxxxx" //根据自己情况更改
//git 配置
def gitlab_auth = "fd5f4a3f-605a-4f72-af49-2b6601565f3b"
def git_address = "http://10.37.1.4:31002/aida-review-service/aida-review-service.git"
podTemplate(label: label, cloud: 'kubernetes',containers: [
containerTemplate(name: 'jnlp-slave', image: 'xxxxx/jnlp-slave:v15') //nlp-slave根据自己情况更改
],
volumes: [ //需要挂载映射目录
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
hostPathVolume(mountPath: '/usr/bin/kubectl', hostPath: '/usr/bin/kubectl'),
hostPathVolume(mountPath: '/etc/docker/daemon.json', hostPath: '/etc/docker/daemon.json'),
hostPathVolume(mountPath: '/opt/maven/repository', hostPath: '/jenkins/maven/repository'),
hostPathVolume(mountPath: '/usr/bin/kubectl', hostPath: '/usr/bin/kubectl')
]) {
node(label) {
stage('deploy start') {
container(label) {
stage('cat the pod env'){
sh 'kubectl get pod -n $Namespace'
sh 'mvn -v'
}
stage('git checkout'){
echo 'git clone'
checkout([$class: 'GitSCM',branches: [[name: '${branch}']], userRemoteConfigs: [[credentialsId: "${gitlab_auth}", url: "${git_address}"]]])
}
stage('Maven package'){
echo 'git clone'
//sh "cd ${env.WORKSPACE}/aida_dom_service/"
sh """
echo ${env.WORKSPACE}
cd ${env.WORKSPACE}
mvn clean package -Dmaven.test.skip=true
"""
}
stage('docker build and push images'){
withCredentials([usernamePassword(credentialsId: "$aliyunhub_auth", usernameVariable: "user", passwordVariable: "passwd")]) {
sh """
docker login -u ${user} -p ${passwd} ${harbor_addr}
scp -r /home/jenkins/skywalking ${env.WORKSPACE}
cd ${env.WORKSPACE}
docker build . -t ${harbor_addr}/ks3_cicd:${build_tag}
#docker tag registry.aidatrans.com/aida/dom:latest hub.kce.ksyun.com/ks3_cicd/ks3_cicd:${build_tag}
docker push ${harbor_addr}/ks3_cicd:${build_tag}
"""
}
}
stage('deploy K8s'){
//sh "mv ./*.yaml ./${build_tag}.yaml"
sh "sed -ri 's#image: hub.kce.ksyun.com.*#image: ${harbor_addr}/ks3_cicd:${build_tag}#g' ./k8s/test-review-deploy-logfile.yaml"
sh "sed -ri 's#namespace: .*#namespace: ${params.Namespace}#g' ./k8s/test-review-deploy-logfile.yaml"
//sh "sed -ri 's/name: .*/name: ${params.Namespace}/' ./${build_tag}.yaml"
sh "mv ./k8s/test-review-deploy-logfile.yaml ./${build_tag}.yaml"
sh "kubectl apply -f ./${build_tag}.yaml --record "
}
}
}
}
}
jenkins集成 配置截图