基于Jenkins+k8s+Git+harbor构建DevOps容器云平台

网友投稿 282 2022-10-24

基于Jenkins+k8s+Git+harbor构建DevOps容器云平台

master1:192.168.40.18

node1: 192.168.40.17

需要有一台harbor服务,我的harbor安装在了192.168.40.17机器上

关于harbor的安装部署后续补充

1.添加凭据

username:admin

password:Harbor12345

ID:dockerharbor

描述:dockerharbor test

2.编写jenkins pipeline

因为镜像要上传到harbor私有镜像仓库,所以需要在harbor上创建一个项目,项目名称是jenkins-demo,如下所示:

上面项目创建成功之后,执行如下步骤:

新建一个任务------>输入一个任务名称处输入jenkins-harbor------>流水线------>确定------>在Pipeline script处输入如下内容

node('testhan') { stage('Clone') { echo "1.Clone Stage" git url: "https://github.com/mygithub/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 192.168.40.17/jenkins-demo/jenkins-demo:${build_tag} ." } stage('Push') { echo "4.Push Docker Image Stage" withCredentials([usernamePassword(credentialsId: 'dockerharbor', passwordVariable: 'Harbor12345', usernameVariable: 'admin')]) { sh "docker login 192.168.40.17 -u ${dockerHubUser} -p ${dockerHubPassword}" sh "docker push 192.168.40.17/jenkins-demo/jenkins-demo:${build_tag}" } } stage('Deploy to dev') { echo "5. Deploy DEV" sh "sed -i 's//${build_tag}/' k8s-dev-harbor.yaml" sh "sed -i 's//${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}/' k8s-qa-harbor.yaml" sh "sed -i 's//${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}/' k8s-prod-harbor.yaml" sh "sed -i 's//${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" } } }

应用------>保存------>立即构建

打开blue ocean查看详细流程

输入YES/NO

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Resty极简restful框架快速接入Spring
下一篇:CPU有哪些接口
相关文章

 发表评论

暂时没有评论,来抢沙发吧~