Jenkins: DirectoryNotEmptyException: …/lastSuccessful

We are running Jenkins 1.651.1 in a Docker container.
On a certain moment we decided to move our containers to another environment.

We have a cron job which creates backups of the volume of our container:

  • How to rebuild docker image on push before CI script jobs
  • How to setup a valid mongo replicaset
  • How do I start cron on docker ubuntu base?
  • Cannot invoke gdb on docker images (on OSX)
  • Can you share Docker containers?
  • Bind Docker to a Unix socket under upstart in kubernetes master node
  • tar -cvpzf jenkins-backup.tar -C jenkins-volume/_data/ . --exclude ".m2"
    

    On the new environment we created a new jenkins docker volume:

    docker volume create --name jenkins-volume
    

    And we untar our backup inside the volume + recreated a jenkins instance and connected it with the volume

    Everything is working fine again except we sometimes get an unexpected ‘error’ message. It doesn’t break anything but appears very often:

    Started by user ********
    ln builds/lastSuccessfulBuild /var/jenkins_home/jobs/xxx/lastSuccessful failed
    java.nio.file.DirectoryNotEmptyException: /var/jenkins_home/jobs/xxx/lastSuccessful
        at sun.nio.fs.UnixFileSystemProvider.implDelete(UnixFileSystemProvider.java:242)
        at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(AbstractFileSystemProvider.java:108)
        at java.nio.file.Files.deleteIfExists(Files.java:1165)
        at sun.reflect.GeneratedMethodAccessor473.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at hudson.Util.createSymlinkJava7(Util.java:1233)
        at hudson.Util.createSymlink(Util.java:1151)
        at hudson.model.Run.createSymlink(Run.java:1840)
        at hudson.model.Run.updateSymlinks(Run.java:1821)
        at hudson.model.Run.execute(Run.java:1736)
        at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
        at hudson.model.ResourceController.execute(ResourceController.java:98)
        at hudson.model.Executor.run(Executor.java:410)
    ln builds/lastStableBuild /var/jenkins_home/jobs/xxx/lastStable failed
    java.nio.file.DirectoryNotEmptyException: /var/jenkins_home/jobs/xxx/lastStable
        at sun.nio.fs.UnixFileSystemProvider.implDelete(UnixFileSystemProvider.java:242)
        at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(AbstractFileSystemProvider.java:108)
        at java.nio.file.Files.deleteIfExists(Files.java:1165)
        at sun.reflect.GeneratedMethodAccessor473.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at hudson.Util.createSymlinkJava7(Util.java:1233)
        at hudson.Util.createSymlink(Util.java:1151)
        at hudson.model.Run.createSymlink(Run.java:1840)
        at hudson.model.Run.updateSymlinks(Run.java:1822)
        at hudson.model.Run.execute(Run.java:1736)
        at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
        at hudson.model.ResourceController.execute(ResourceController.java:98)
        at hudson.model.Executor.run(Executor.java:410)
    [EnvInject] - Loading node environment variables.
    Building in workspace /var/jenkins_home/jobs/xxx/workspace
     > git rev-parse --is-inside-work-tree # timeout=10
    ... and it works further and fine
    

    What is the best way to solve this?

  • AWS elastic beanstalk not mounting docker volumes
  • Does the GOGS Docker Container run an SSH Daemon?
  • Using a Makefile to get latest git tag
  • Appcrash KERNELBASE.dll error when I try to use Microsoft Office in Docker Container
  • CoreOS + Docker - Assign Containers a pool of routable IP's
  • How to improve Kubernetes security especially inter-Pods?
  • One Solution collect form web for “Jenkins: DirectoryNotEmptyException: …/lastSuccessful”

    As commented by CSchulz you can delete the directories and those will get created base on the result of the build.

    This could also be because these are soft links & from the backup, these might be created as the directories. Hence, Jenkins not able to delete them.
    If you remove or rename these directories, Jenkins then can recreate the soft-links.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.