| I have tried to build images on my k8s cluster using kaniko and the kubernetes-plugin, while for some images the process works just fine for others I encountered a misbehaviour. In particular, the Jenkins build logs are flooded with the following lines, making the build fail :
*12:51:38* sh: sleep: not found
*12:51:38* sh: touch: not found
I tried to debug the issue and eventually, I realized that Jenkins is running a command using nohup that is not able to find the sleep and touch utilities (the kaniko image is extremely minimal) because they are not in the folder where Jenkins expects them, but they are under the /busybox folder. I managed to mitigate the problem adding an env variables in order to overwrite the path:
stages {
stage('Build with Kaniko') {
environment {
PATH = "/busybox:$PATH"
}
steps {
container(name: 'kaniko', shell: '/busybox/sh') {
sh '''#!/busybox/sh
/kaniko/executor -v warn -f `pwd`/Dockerfile -c `pwd` -d 'gcr.io/camunda-public/bpmn-io-demo:tmp'
'''
}
}
}
}
This approach partially fixes the problem. The logs are still flooded, but for a shorter period of time. Moreover, the following line appear at a certain point.
12:51:38 sh: touch: not found
12:51:39 sh: sleep: not found
12:51:39 sh: touch: not found
12:51:39 sh: sleep: Text file busy
12:51:39 sh: touch: Text file busy
12:51:39 sh: sleep: Text file busy
I am very confident that the responsible of this is the following line: https://github.com/jenkinsci/kubernetes-plugin/blob/6f5db53a096b241a7cb6bb9f26e898f5c2e04f38/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/ContainerExecDecorator.java#L531 since I can see in the debug log that a small bash script using the sleep/touch commands is called by Jenkins using nohup. I believe the problem is related (but I haven't verified) only to Docker multi-stage builds. |