分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

jenkins docker-plugin 和 kubernetes-plugin插件实用案例

发布时间:2023-09-06 01:36责任编辑:赖小花关键词:kubernetes
Jenkins docker-plugin的使用方法:
node { ???????stage(‘Clone Code‘) { ???????????????dir(‘baas-ops‘) { ???????????????????????git credentialsId: ‘umarkci‘, url: ‘git@github.******.com:umark/baas-ops.git‘ ???????????????} ???????} ???????stage(‘Unit testing‘) { ???????????????docker.image(‘busybox‘).inside { ???????????????????????sh ‘echo "Unit testing step !!!"‘ ???????????????} ???????} ???????stage(‘Build‘) { ???????????????docker.image(‘busybox‘).inside { ???????????????????????sh ‘echo ?Build step !!!‘ ???????????????} ???????} ???????stage(‘Image Build And Push‘) { ???????????????dir(‘baas-ops/oboe/cli‘) { ????????????????????docker.withRegistry(‘https://registry.******.com:8080‘, ‘registry-hub-credentials‘) { ???????????????????????????????docker.build(‘oboe-cli‘).push(‘t1‘) ???????????????????????} ????????????????} ???????} ???????stage(‘Deploy images‘) { ???????????????try { ???????????????????????sh ‘docker rm -f test‘ ???????????????} catch(e) { ???????????????} ???????????????docker.image(‘oboe-cli:t1‘).run(‘-p 80:3000 --name test‘) ???????}}

jenkins kubernetes-plugin 插件使用:

podTemplate(label: ‘test‘, securityContext: [ runAsUser: ‘root‘], ???containers: [ ???????containerTemplate(name: ‘jnlp‘, image: ‘registry.******.com:8088/jnlp-slave:alpine‘, args: ‘${computer.jnlpmac} ${computer.name}‘), ???????containerTemplate(name: ‘docker‘, image: ‘docker:stable‘, ttyEnabled: true, command: ‘cat‘) ???????], ???volumes: [ ???????????hostPathVolume(hostPath: ‘/var/run/docker.sock‘, mountPath: ‘/var/run/docker.sock‘), ???????// ??hostPathVolume(hostPath: ‘/tmp/test‘, mountPath: ‘/data‘), ???????????persistentVolumeClaim(claimName: ‘jenkins-slave-gfs‘, mountPath: ‘/home/jenkins‘, readOnly: false) ???????], ???) { ???node(‘test‘) { ???????def registryAddr=‘registry.******.com:8080‘ ???????stage(‘build image‘) { ???????????????git credentialsId: ‘oschina-test‘, url: ‘git@gitee.com:yonchin/jenkins-test.git‘ ???????????????container(‘docker‘) { ???????????????????????sh "docker build -t ${registryAddr}/busybox:k8s ." ???????????????} ???????} ???????stage(‘push image‘) { ???????????????container(‘docker‘) { ???????????????????????withCredentials([usernamePassword(credentialsId: ‘registry-hub-credentials‘, passwordVariable: ‘registryPass‘, usernameVariable: ‘registryUser‘)]) { ???????????????????????????????sh "docker login ${registryAddr} -u ${env.registryUser} -p ${registryPass}" ???????????????????????????????sh "docker push ${registryAddr}/busybox:k8s" ???????????????????????} ???????????????} ???????} ???}}注: 其中 credentialsId 是要在jenkins -> credentials -> system -> Global credentials (unrestricted) -> Add credentials 中事先创建好。 其中,registryUser 和 registryPass 这两个变量会自动获取在‘Add credentials’中定义对用户名和密码。

jenkins docker-plugin 和 kubernetes-plugin插件实用案例

原文地址:http://blog.51cto.com/noican/2061008

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved