jenkins流水线部署,项目一键部署到k8s,项目一键部署K8S
jenkins流水线部署,项目一键部署到k8s,项目一键部署K8S
·
-
预操作
https://blog.51cto.com/wzlinux/2160109
用以在后面的Jenkinsfile中进行配置。
-
Jenkinsfile
node { def appimage def registry = '项目仓库相对路径' def registryCredential = 'aliyun-docker-image-repository' // 第一步 拉取代码 stage("Checkout"){ checkout([$class: 'GitSCM', branches: [[name: '*/'+env.BRANCH_NAME]], extensions: [[$class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: false, recursiveSubmodules: true, reference: '', trackingSubmodules: false]], userRemoteConfigs: [[credentialsId: 'd423a59c-2f90-42d9-dd6c39f0033c', url: '项目Git地址']]]) } // 打包镜像 stage('Build') { appimage = docker.build registry + ":" + env.BRANCH_NAME + "-$BUILD_NUMBER" } // 推送镜像 stage('Publish') { docker.withRegistry('https://registry-vpc.cn-beijing.aliyuncs.com', registryCredential ) { appimage.push() appimage.push(env.BRANCH_NAME) } } // 服务部署 stage('Deploy') { def img = "镜像仓库绝对路径:" + env.BRANCH_NAME + "-$BUILD_NUMBER" def namespace if (env.BRANCH_NAME == 'master' ) { namespace = 'dev' } else if (env.BRANCH_NAME == 'staging' ) { namespace = 'staging' } else if (env.BRANCH_NAME == 'production' ) { namespace = 'production' } sh "kubectl set image deployment/scheduler ranking-scheduler="+img+" --record --namespace "+namespace } }
更多推荐
已为社区贡献5条内容
所有评论(0)