Clean up unused workspaces on the controller node (running in kubernetes)?

I am deploying jenkins in kubernetes using this helm chart:

I have lots of projects using the multibranch pipeline job and see a lot of folders on the controller node in this folder:

/var/jenkins_home/workspace

How do I enable automatic cleanup/retention on those folders?

I have looked at:

but from what I can see thats for the workspace on the agents - which does not really make much sense in kubernetes because the disappear anyway when the pipeline/job terminates.

See Jenkins Features Controlled with System Properties
But I’m not sure if this will cleanup workspace on the controller as well. If not you would need to write a system groovy script run inside a freestyle job that does the same thing.

Are you using your main controller as an agent? Then cleaning up agents make sense.
Otherwise what is in that folder? I don’t know why a controller would have workspace.

No I have number of executors = 0 for the controller node (built-in node).

There is a git clone per job per branch per multibranch pipeline job its seems. E.g.:

$ ls -la /var/jenkins_home/workspace/
total 100
drwxrwsr-x 24 jenkins jenkins 4096 Jul 18 17:44 .
drwxrwsr-x 20 root    jenkins 4096 Jul 21 05:57 ..
drwxr-sr-x  6 jenkins jenkins 4096 Jul 15 07:12 FEATURE_01@libs
drwxr-sr-x  6 jenkins jenkins 4096 Jul 15 07:12 feature1@libs
drwxr-sr-x  6 jenkins jenkins 4096 Jul 15 07:12 myfolder

....
drwxr-sr-x  4 jenkins jenkins 4096 Jul 18 17:44 featurexxx@script
drwxr-sr-x  4 jenkins jenkins 4096 Jul 18 17:41 feratureddd@script
-rw-r--r--  1 jenkins jenkins 1568 Jul 15 21:21 workspaces.txt


$ ls -la  /var/jenkins_home/workspace/myfolder/myjob@script/
total 20
drwxr-sr-x 4 jenkins jenkins 4096 Jul 19 15:01 .
drwxrwsr-x 6 jenkins jenkins 4096 Jul 19 15:01 ..
drwxr-sr-x 8 jenkins jenkins 4096 Jul 19 15:01 44ed3fb2986e3aeb344a102sc94975acab0b12e1acc9f8379d761816934ead92
-rw-r--r-- 1 jenkins jenkins   49 Jul 19 15:30 44ed3fb2986e3aeb344a102sc94975acab0b12e1acc9f8379d761816934ead92-scm-key.txt
drwxr-sr-x 2 jenkins jenkins 4096 Jul 19 15:30 44ed3fb2986e3aeb344a102sc94975acab0b12e1acc9f8379d761816934ead92@tmp

$ ls -la  /var/jenkins_home/workspace/myfolder/myjob@script/44ed3fb2986e3aeb344a102sc94975acab0b12e1acc9f8379d761816934ead92
total 92
drwxr-sr-x 8 jenkins jenkins 4096 Jul 19 15:01 .
drwxr-sr-x 4 jenkins jenkins 4096 Jul 19 15:01 ..
drwxr-sr-x 8 jenkins jenkins 4096 Jul 19 15:30 .git
-rw-r--r-- 1 jenkins jenkins  444 Jul 19 15:01 .gitignore
-rw-r--r-- 1 jenkins jenkins 1850 Jul 19 15:01 Jenkinsfile
-rw-r--r-- 1 jenkins jenkins 6420 Jul 19 15:01 README.md
-rw-r--r-- 1 jenkins jenkins 4959 Jul 19 15:01 build.gradle
drwxr-sr-x 3 jenkins jenkins 4096 Jul 19 15:01 gradle
-rw-r--r-- 1 jenkins jenkins  550 Jul 19 15:01 gradle.properties
drwxr-sr-x 5 jenkins jenkins 4096 Jul 19 15:01 src

Maybe its because the multibranch pipeline job can needs to run on master and it needs a clone of each job per branch in the workspace on the controller node to see if a new branch is available?

Hi, I have the exact same issue, I was wondering if you managed to solve that?