After creating a copy of the local Jenkins home lastSuccessful fails with java.nio.file.DirectoryNotEmptyException

Article ID:215281777
2 minute readKnowledge base


  • After creating a copy of the local Jenkins home /lastSuccessful fails with java.nio.file.DirectoryNotEmptyException

  • You are getting a stacktrace similar to the one below:

/opt/jenkins/jobs/PACE/jobs/Scheduled_Production_Copy_LPAR6/lastSuccessful failed
java.nio.file.DirectoryNotEmptyException: /opt/jenkins/jobs/PACE/jobs/Scheduled_Production_Copy_LPAR6/lastSuccessful
at sun.nio.fs.UnixFileSystemProvider.implDelete(
at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(
at java.nio.file.Files.deleteIfExists(
at sun.reflect.GeneratedMethodAccessor4202.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at hudson.Util.createSymlinkJava7(
at hudson.Util.createSymlink(
at hudson.model.Run.createSymlink(
at hudson.model.Run.updateSymlinks(
at hudson.model.Run.execute(
at hudson.model.ResourceController.execute(


The issue is related to the method used to copy the $JENKINS_HOME from one location to another one, which in this particular case broke the symlinks.

The recommended option, it is to rollback to a security copy of your previous $JENKINS_HOME if possible and copy it in the new location using a method which preserve the symlinks.

If this is not possible, to fix the controller where you have these erroneous directories you should follow the steps shown below:

Important Notice: You should have a current backup of your $JENKINS_HOME or you should create one before trying the method described below.

# Logon on the controller where you have the issue
ssh machine
# Shutdown the jenkins controller (take care that nothing is running)
sudo service jenkins stop
# Find all erroneous directories
find /opt/jenkins/jobs -type d \( -name "last*Build" -o -name "lastStable" -o -name "lastSuccessful" \)
# Review the list of erroneous directories
# Rename them
find /opt/jenkins/jobs -type d \( -name "last*Build" -o -name "lastStable" -o -name "lastSuccessful" \) -exec mv {} {}.err \;
# Restart jenkins
sudo service jenkins start

Once that you have verified that everything is working correctly, you should delete the faulty directories following the steps shown below:

# Delete them
find /opt/jenkins/jobs -type d -name "*.err" -exec rm -rf {} \;

Tested product/plugin versions