sunfull 发表于 2018-9-3 12:17:42

jenkins docker-plugin 和 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() {
  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’中定义对用户名和密码。

页: [1]
查看完整版本: jenkins docker-plugin 和 kubernetes-plugin插件实用案例