Problem using Kaniko to build containers from a Kubernetes CloudBees Jenkins shared-library

5/10/2019

I am trying to build containers using a Jenkins shared-library that calls Kaniko. Jenkins is CloudBees Core running on a Kubernetes cluster.

I prefer to try to use pod templates to build containers, but I can fall back to a dedicated VM if I have to (but my client will not be happy).

The problem: running Kaniko from a simple Jenkinsfile pipeline works fine, but I am getting errors when trying to run it from a shared-library.

The snippet of my shared-library:

docker.image('kaniko').inside('-u root --privileged') {
       sh '''#!/busybox/sh
            /kaniko/executor --context `pwd` --destination docker.artifactory.company.com/docker-local/hello-kaniko:latest
            '''
    }

The error I get (snipped):

.
.
.
Building: default
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] sh
+ docker inspect -f . kaniko
/home/jenkins/workspace/cloud-services@tmp/durable-28d8debd/script.sh: line 1: docker: not found
[Pipeline] sh
+ docker pull kaniko
/home/jenkins/workspace/cloud-services@tmp/durable-dc065568/script.sh: line 1: docker: not found
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE

Has anyone else been able to get Kaniko running from a shared-library in Jenkins on Kubernetes?

-- tdensmore
dockerfile
jenkins-shared-libraries
kaniko
kubernetes

1 Answer

7/11/2019

I had a similar problem in kaniko container, what i had to do was add PATH to the environment:

    withEnv(['PATH+EXTRA=/busybox:/kaniko']) {
      sh '''#!/busybox/sh
      /kaniko/executor (....)
    }
-- kovalsky
Source: StackOverflow