git pipeline 指定 tag

Submitted by Lizhe on Thu, 07/18/2019 - 15:28

def label = "mypod-${UUID.randomUUID().toString()}"
podTemplate(label: label, yaml: """
kind: Pod
metadata:
  name: kaniko
spec:
  containers:
  - name: kaniko
    image: gcr.io/kaniko-project/executor:debug
    imagePullPolicy: Always
    command:
    - /busybox/cat
    tty: true
    volumeMounts:
      - name: jenkins-docker-cfg
        mountPath: /root
  volumes:
  - name: jenkins-docker-cfg
    projected:
      sources:
      - secret:
          name: regcred
          items:
            - key: .dockerconfigjson
              path: .docker/config.json
"""
) {
    node(label) {
    stage('Build with Kaniko') {
      sh label: '', script: 'free -m'
      timeout(time: 2, unit: 'HOURS'){
        dir('ab7files') {
          checkout scm: [$class: 'GitSCM', userRemoteConfigs: [[url: 'xxxxxx.git', credentialsId: 'xxxxxxx']], branches: [[name: 'refs/tags/v1.0.0']]],poll: false
        }
      }
      timeout(time: 2, unit: 'HOURS'){
        dir('hybrisfiles') {
          git branch: 'master', credentialsId: 'xxxxxx', url: 'xxxxxx.git'
        }
      }
      timeout(time: 2, unit: 'HOURS'){
        dir('tools') {
          git branch: 'master', credentialsId: 'xxxxxx', url: 'xxxxxxxx.git'
        }
      }
      timeout(time: 2, unit: 'HOURS'){
        dir('dockersource') {
          git branch: 'master', credentialsId: 'xxxxxxxxxxx', url: 'xxxxxxxxxxxx.git'
        }
      }


      container(name: 'kaniko', shell: '/busybox/sh') {
        withEnv(['PATH+EXTRA=/busybox:/kaniko']) {
          sh '''#!/busybox/sh
          /kaniko/executor -f /home/jenkins/workspace/buildhybris/dockersource/hybris/Dockerfile -c `pwd` --destination=xxxx/xxxx:test0.1
          '''
        }
      }
    }
  }
}