Monday 20 December 2021

Jenkins cannot delete root-owned files/folders in jenkins-owned directories

 In this post we will discuss abut most frequent issues faced in Jenkins build.

When you try to use docker image to run your jobs you may end up in creating some file which are created by root user ( from Docker image ). In this case from next build onwards we will see some issues to clean old workspace. Even if you try to use cleanUP workspace plugin you will end up with permission issues. 

To avoid this issue please follow below steps
1) Install acl package based on your distribution.

 Debian
apt-get install acl
 Ubuntu
apt-get install acl
 Alpine
apk add acl
 Arch Linux
pacman -S acl
 Kali Linux
apt-get install acl
 CentOS
yum install acl
 Fedora
dnf install acl
2) Follow below steps to clean workspace and apply acl on workspace folder. After this change you will see any file or folder which is created in workspace folder will have complete ownership of jenkins user. 
$ rm -rf workspace # to avoid any inconsistencies in existing files
$ mkdir workspace
$ sudo setfacl -dm 'u:<your_jenkins_user_name>:rwx' workspace