从jenkins groovy管道将kaniko构建映像推送到Azure容器注册表时发生错误

时间:2018-11-24 18:08:31

标签: jenkins kubernetes azure-devops jenkins-groovy azure-kubernetes

我有一个场景,我在Minikube的K8s集群中运行我的Jenkins。我在Jenkins Pipeline中运行了一个groovy脚本,该脚本构建了docker映像 使用 Kaniko (可构建没有docker守护程序的docker映像)并推送到Azure容器注册表。我创建了用于身份验证Azure的秘密。

但是当我推送图像时-出现错误

 " [36mINFO[0m[0004] Taking snapshot of files...                  
[36mINFO[0m[0004] ENTRYPOINT ["jenkins-slave"]                 
error pushing image: failed to push to destination Testimage.azurecr.io/test:latest: unexpected end of JSON input
[Pipeline] }"

我的脚本

My groovy script -- 

def label = "kaniko-${UUID.randomUUID().toString()}"

podTemplate(name: 'kaniko', 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-pv
        mountPath: /root
  volumes:
  - name: jenkins-pv
    projected:
      sources:
      - secret:
          name: pass
          items:
            - key: .dockerconfigjson
              path: .docker/config.json
"""
  ) {

  node(label) {
    stage('Build with Kaniko') {
      git 'https://github.com/jenkinsci/docker-jnlp-slave.git'
      container(name: 'kaniko', shell: '/busybox/sh') {
          sh '''#!/busybox/sh
          /kaniko/executor -f `pwd`/Dockerfile -c `pwd` --skip-tls-verify --destination=testimage.azurecr.io/test:latest
          '''
      }
    }
  }
}

请帮助您解决错误?还有:

  • 我怎么知道kaiko构建的图像的名称?
  • 我只是想像-registry.acr.io/ 测试:最新,可能是图像名称不正确,这就是我收到JSON输出错误的原因吗?

0 个答案:

没有答案