Why is Jenkins suddenly unable to delete a workspace
This page still gets a lot of attention, and this is probably the correct answer to my original question.
I had the same problem, found some files with permission root:root in the workspace directory. Running "sudo chown -R jenkins:jenkins /var/lib/jenkins/workspace" solved the problem.
Thanks to Olivier Boudry
As a temporary solution, try renaming your project.
I finally found the solution that explains everything.
Cause:
I was using docker within Jenkins and mounted Jenkins work directory in Docker (-v pwd:/code:rw
).
During runtime my program generate few files that also goes in to Jenkins work directory as it is mounted. but the user is docker root not Jenkins user, because of that Jenkins user is unable to delete those files and cause this error.
Solution: you can also share Jenkins user with docker, So all file created is same as file created by Jenkins itself.
docker run --user "$(id -u):$(id -g)" -i --rm -v /etc/passwd:/etc/passwd:ro -v `pwd`:/code:rw docker_image:tag
So Adding This basically solve the issue by Using Jenkins user inside docker.
--user "$(id -u):$(id -g)" -v /etc/passwd:/etc/passwd:ro
There is something locking the file or directory in the workspace.
- Someone has logged into Jenkins and is accessing the files from the workspace directly using the file system but not via Jenkins.
- The build process left a zombie program.
Some other similar cases.
If you have the shell access to FS use something like lsof
to find the locking process.
EDIT: After several votes I implemented several items on some linux and windows slaves.
In my case I know the names of the possible zombies.
I added a special job/build that kills processes that might be left in linux.
In windows I wrote a CS program that kills possible processes and/or runs the 'UnLock IT' with the Jenkins job that also frees up resources.