Jenkins-Kubernetes-docker-自动发布
使用的是Jenkins pipeline:
这里只是做了更新,没有创建,没有借助helm等工具,先用着,以后再研究。
pipeline { agent any stages { stage("发布") { steps { sh 'dotnet publish -c release' } } stage("创建ciswebapi镜像") { steps { sh 'docker build -t ciswebapi src/Cis.IMP.WebApi/bin/Release/netcoreapp2.0/publish/' sh 'docker tag ciswebapi ip:5000/ciswebapi:${BUILD_NUMBER}' sh 'docker push ip:5000/ciswebapi:${BUILD_NUMBER}' } } stage("创建cisweb镜像") { steps { sh 'docker build -t cisweb src/Cis.IMP.Web/bin/Release/netcoreapp2.0/publish/' sh 'docker tag cisweb ip:5000/cisweb:${BUILD_NUMBER}' sh 'docker push ip:5000/cisweb:${BUILD_NUMBER}' } } stage("远程调用k8s更新镜像cisweb") { steps { sh 'ssh -t -t root@nodeip "kubectl set image deployment/cisweb cisweb=ip:5000/cisweb:${BUILD_NUMBER}"' } } stage("远程调用k8s更新镜像ciswebapi") { steps { sh 'ssh -t -t root@nodeip "kubectl set image deployment/ciswebapi ciswebapi=ip:5000/ciswebapi:${BUILD_NUMBER}"' } } } post { always { sh 'echo "Complete"' } } }
执行效果:如下图: