I have a Ubuntu VM with an installed Docker engine, a K3S cluster including Jenkins 2.511, and a JDK 21 pod.
I have been struggling with this kind of error for several days:
cp: can't stat '/var/jenkins_home/jobs/<job_name>/branches/develop/workspace@tmp/durable-1bc899cb/script.sh': No such file or directory sh: can't create /var/jenkins_home/jobs/<job_name>/branches/develop/workspace@tmp/durable-1bc899cb/jenkins-log.txt: nonexistent directory sh: can't create /var/jenkins_home/jobs/<job_name>/develop/workspace@tmp/durable-1bc899cb/jenkins-result.txt.tmp: nonexistent directory mv: can't rename'/var/jenkins_home/jobs/<job_name>/branches/develop/workspace@tmp/durable-1bc899cb/jenkins-result.txt.tmp': No such file or directory
I also saw this thread, where it has been discussed, however, none of these proposals worked for me.
The volume where /var/jenkins_home resides has been added to the container running on the host (VM), but I still received the same error, despite that the /var/docker/docker.sock from the host worked correctly. What is the solution?
Inspired by the official documentation of the Jenkins Docker pipeline plugin, I subsequently decided to create Jenkins agent residing on the VM. Specifically, the described part in the image helped me.
The Docker server and Jenkins agent must use the same filesystem. I decided to create a Jenkins agent with SSH access to the VM (host) and used the label node in my Jenkinsfile:
pipeline {
agent {
label 'my-vm-node'
}
stages {
stage('Build in Docker') {
steps {
script {
docker.withRegistry('https://docker-registry.com/v2/', 'my-docker-registry-cred') {
docker.image('my-image').inside('-u 0') {
stage('Compile') {
sh 'mvn version'
}
}
}
}
}
}
}
}
This the only solution I explored after 10 days.