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:

  • Seeding a MySQL DB for a Dockerized Django App
  • Travis-CI: docker image as build environment
  • Jenkins Github Plugin can't choose my credentials
  • docker containers communication on dev machine
  • How to remove file/folder from Docker container without starting this container
  • Trying to transfer big file docker container Error response from daemon: ApplyLayer exit status 1 stdout: stderr: unexpected EOF
  • 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?

  • Load balancing is not working properly
  • How to deploy multiple docker.io containers in one host?
  • Install Firefox on Tinycore (Docker)
  • Active directory accounts inside a windows container (server 2016 TP5)
  • How to define docker image name from within docker-compose.yml?
  • Craft CMS Manager Craftman - No such file or directory: '//docker-compose.yml'
  • 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.