Jenkins specified tag issued to k8s environment
1, Jenkins configure a Pipeline Project
You must first install the plugin: https://www.cnblogs.com/Dev0ps/p/9125232.html
Parametric build process
Pipeline选择Pipeline script from SCM
After the failure will be prompted to save the building can not find Jenkinsfile, we just need to create the appropriate file to Jenkinsfile
vim /root/.jenkins/workspace/sscp-xxx_sit@script/Jenkinsfile
node (){ //指定Slave标签 stage('Git Checkout') { checkout([$class: 'GitSCM', branches: [[name: '${Tag}']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: '[email protected]:xx/xx.git']]]) } //代码编译 stage('Maven Build') { sh ''' export JAVA_HOME=/usr/local/java /usr/local/maven/bin/mvn clean package -Ppresit -Dmaven.test.skip=true ''' } stage('Build and Push Image') { sh ''' REPOSITORY=172.31.182.143/presit/sscp-xxx:${Tag} cp Dockerfile target/ cd target docker build -t $REPOSITORY . docker login -u admin -p Harbor%12345 172.31.182.143 docker push $REPOSITORY ''' } stage('Deploy to k8s') { sh ''' K8S_MASTER="172.31.182.152" APP="sscp-xxx" ENV="presit" ssh ${K8S_MASTER} -t "cd /root/helm/source/sscp-config/sscp-${ENV}/sscp-deploy-config;git checkout ${ENV};git pull" ssh ${K8S_MASTER} cp /root/helm/source/sscp-config/sscp-${ENV}/sscp-deploy-config/${APP}/values.yaml /root/helm/sscp-${ENV}/${APP}/values.yaml ssh ${K8S_MASTER} helm upgrade ${APP}-${ENV} -f /root/helm/sscp-${ENV}/${APP}/values.yaml --set app.updateVersion=`date +%s` chartmuseum/${APP} --set app.image.tag=${Tag} ''' } }
Building effects again: