Error pushing kaniko build image to azure container registry from jenkins groovy pipeline

11/24/2018

I have a scenario, I run my Jenkins in K8s cluster in Minikube. I run a groovy script within my Jenkins Pipeline which builds the docker image using Kaniko (which builds a docker image without docker daemon) and pushes to Azure container registry. I have created secret to authenticate to Azure.

But when I push an image - I get an error

 " [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 Script

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
          '''
      }
    }
  }
}

Could you please help how to overcome the error? And also :

  • How do I know the name of the image build by kaiko?
  • I m just pushing like - registry.acr.io/test: latest, probably it's an incorrect image name that's the reason I get JSON output error?
-- user2153844
azure-devops
azure-kubernetes
jenkins
jenkins-groovy
kubernetes

0 Answers