k8s部署jenkins+流水线发布开发-测试-线上环境(效果图)
效果完成图
pipline
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | node( 'testhan' ) { stage( 'Clone' ) { echo "1.Clone Stage" git url: "https://github.com/mazhenk/jenkins-sample.git" script { build_tag = sh(returnStdout: true , script: 'git rev-parse --short HEAD' ).trim() } } stage( 'Test' ) { echo "2.Test Stage" } stage( 'Build' ) { echo "3.Build Docker Image Stage" sh "docker build -t harbor-ioscar.cbf.com/jenkins-demo/jenkins-demo:${build_tag} ." } stage( 'Push' ) { echo "4.Push Docker Image Stage" withCredentials([usernamePassword(credentialsId: 'dockerharbor' , passwordVariable: 'dockerHubPassword' , usernameVariable: 'dockerHubUser' )]) { sh "docker login harbor-ioscar.cbf.com -u ${dockerHubUser} -p ${dockerHubPassword}" sh "docker push harbor-ioscar.cbf.com/jenkins-demo/jenkins-demo:${build_tag}" } } stage( 'Deploy to dev' ) { echo "5. Deploy DEV" sh "sed -i 's/<BUILD_TAG>/${build_tag}/' k8s-dev-harbor.yaml" sh "sed -i 's/<BRANCH_NAME>/${env.BRANCH_NAME}/' k8s-dev-harbor.yaml" // sh "bash running-devlopment.sh" sh "kubectl apply -f k8s-dev-harbor.yaml --validate=false" } stage( 'Promote to qa' ) { def userInput = input( id : 'userInput' , message: 'Promote to qa?' , parameters: [ [ $class: 'ChoiceParameterDefinition' , choices: "YES\nNO" , name: 'Env' ] ] ) echo "This is a deploy step to ${userInput}" if (userInput == "YES" ) { sh "sed -i 's/<BUILD_TAG>/${build_tag}/' k8s-qa-harbor.yaml" sh "sed -i 's/<BRANCH_NAME>/${env.BRANCH_NAME}/' k8s-qa-harbor.yaml" // sh "bash running-qa.sh" sh "kubectl apply -f k8s-qa-harbor.yaml --validate=false" sh "sleep 6" sh "kubectl get pods -n qatest" } else { //exit } } stage( 'Promote to pro' ) { def userInput = input( id : 'userInput' , message: 'Promote to pro?' , parameters: [ [ $class: 'ChoiceParameterDefinition' , choices: "YES\nNO" , name: 'Env' ] ] ) echo "This is a deploy step to ${userInput}" if (userInput == "YES" ) { sh "sed -i 's/<BUILD_TAG>/${build_tag}/' k8s-prod-harbor.yaml" sh "sed -i 's/<BRANCH_NAME>/${env.BRANCH_NAME}/' k8s-prod-harbor.yaml" // sh "bash running-production.sh" sh "cat k8s-prod-harbor.yaml" sh "kubectl apply -f k8s-prod-harbor.yaml --record --validate=false" } } } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?