k8s-jenkins 自动化1

一个流水线例子:

设置参数化构建:

流水线指令:

def label = "docker-${UUID.randomUUID().toString()}"
podTemplate(label: label, yaml: """
apiVersion: v1
kind: Pod
metadata:
  name: docker-default
  namespace: kube-ops 
spec:
  hostNetwork: true
  containers:
  - name: docker
    image: ${imageSlave}
    command: ['cat']
    tty: true
    volumeMounts:
    - name: dockersock
      mountPath: /var/run/docker.sock
  volumes:
  - name: dockersock
    hostPath:
      path: /var/run/docker.sock
"""
  ) {

  node(label) {
    stage('Build Docker image') {
      container('docker') {
        sh "docker login --username ${regUser} --password ${regPasswd} ${regUrl}"
        sh "docker images"
      }
    }
  }
}

  

原文地址:https://www.cnblogs.com/kuku0223/p/10634706.html