How can I clean the workspace in Windows agents?

Issue

We are having problems cleaning up the build workspace when using Git plugin in Windows nodes, this is happening the second time that we run the job on the same agent without restarting it.

[WS-CLEANUP] Deleting project workspace... 
ERROR: [WS-CLEANUP] Cannot delete workspace: remote file operation faileX: X:\Folder\workspace\XXX\XXX at hudson.remoting.Channel@xxxxx:JNLP4-connect connection from XXX: java.nio.file.AccessDeniedException: X:\Folder\workspace\XXX\XXX -> X:\Folder\workspace\XXX\XXX_ws-cleanup_xxxx 
ERROR: Cannot delete workspace: remote file operation faileX: X:\Folder\workspace\XXX\XXX at hudson.remoting.Channel@xxxxx:JNLP4-connect connection from XXX: java.nio.file.AccessDeniedException: X:\Folder\workspace\XXX\XXX -> X:\Folder\workspace\XXX\XXX_ws-cleanup_xxxx

This will not work even if you exclude the files reported as blocked using excusions.

This kind of configuration will result on an error like the one shown below:

Wiping out workspace first. 
java.nio.file.FileSystemException: X:\Folder\workspace\XXX\XXX\.git\objects\pack\pack-xxxxxxxxxxx.pack: The process cannot access the file because it is being used by another process.

Environment

Resolution

You need to add an additional behavior in the Git Plugin section that performs a Clean before checkout operation as shown below:

Workaround

Tested product/plugin versions

Have more questions?

0 Comments

Please sign in to leave a comment.