Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-44657

Build history not copied after renaming the job's parent folder when using custom build directories

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • core
    • None
    • Jenkins 2.46.3; Mac OS X

      If you have configured Jenkins to use custom build directories and then rename a folder, the builds from any jobs in those folders are not correctly copied to the target folder.

      Steps to reproduce

      1. Configure Jenkins to use a custom build directory
      2. Create a folder
      3. In that folder, create a freestyle job
      3.1. Add a shell step with the text "artifact.txt"
      3.2. Add a post-build action to archive the artifacts
      4. Run the freestyle job
      5. See that the builds are showing up in the custom build directory
      6. Rename the folder
      7. Navigate to the job in the new folder
      8. Click on the build run earlier

      Actual Result

      The build logs and artifacts are missing from build #1 as seen in the screen shot after rename. Furthermore, if you restart Jenkins, the build history is completely lost.

      Expected Result

      The build logs and artifacts should not be lost. Restarting Jenkins should not result in the loss of build history.

          [JENKINS-44657] Build history not copied after renaming the job's parent folder when using custom build directories

          Ryan Campbell added a comment -

          I also observe that the original build directory is not actually renamed at all:

          ➜  external-builds ls -lR original-folder/the-job\ /1
          original-folder/the-job /1:
          total 12
          drwxr-xr-x 3 recampbell staff 102 Jun  2 15:38 archive
          -rw-r--r-- 1 recampbell staff 873 Jun  2 15:38 build.xml
          -rw-r--r-- 1 recampbell staff   6 Jun  2 15:38 changelog.xml
          -rw-r--r-- 1 recampbell staff 548 Jun  2 15:38 log
          
          original-folder/the-job /1/archive:
          total 0
          -rw-r--r-- 1 recampbell staff 0 Jun  2 15:38 artifact.txt
          

          but the new location of the build seems to just be a symlink to itself, which makes it unsurprising that the build history is lost upon restart.

          ➜  JENKINS-33941-builds ls -lR renamed-folder/the-job\ /1
          lrwxr-xr-x 1 recampbell staff 1 Jun  2 15:40 renamed-folder/the-job /1 -> 1
          ➜  JENKINS-33941-builds ls -lR renamed-folder/
          renamed-folder/:
          total 0
          drwxr-xr-x 8 recampbell staff 272 Jun  2 15:40 the-job
          
          renamed-folder/the-job :
          total 24
          lrwxr-xr-x 1 recampbell staff 1 Jun  2 15:40 1 -> 1
          lrwxr-xr-x 1 recampbell staff 2 Jun  2 15:40 lastFailedBuild -> -1
          lrwxr-xr-x 1 recampbell staff 1 Jun  2 15:40 lastStableBuild -> 1
          lrwxr-xr-x 1 recampbell staff 1 Jun  2 15:40 lastSuccessfulBuild -> 1
          lrwxr-xr-x 1 recampbell staff 2 Jun  2 15:40 lastUnstableBuild -> -1
          lrwxr-xr-x 1 recampbell staff 2 Jun  2 15:40 lastUnsuccessfulBuild -> -1
          

          Ryan Campbell added a comment - I also observe that the original build directory is not actually renamed at all: ➜ external-builds ls -lR original-folder/the-job\ /1 original-folder/the-job /1: total 12 drwxr-xr-x 3 recampbell staff 102 Jun 2 15:38 archive -rw-r--r-- 1 recampbell staff 873 Jun 2 15:38 build.xml -rw-r--r-- 1 recampbell staff 6 Jun 2 15:38 changelog.xml -rw-r--r-- 1 recampbell staff 548 Jun 2 15:38 log original-folder/the-job /1/archive: total 0 -rw-r--r-- 1 recampbell staff 0 Jun 2 15:38 artifact.txt but the new location of the build seems to just be a symlink to itself, which makes it unsurprising that the build history is lost upon restart. ➜ JENKINS-33941-builds ls -lR renamed-folder/the-job\ /1 lrwxr-xr-x 1 recampbell staff 1 Jun 2 15:40 renamed-folder/the-job /1 -> 1 ➜ JENKINS-33941-builds ls -lR renamed-folder/ renamed-folder/: total 0 drwxr-xr-x 8 recampbell staff 272 Jun 2 15:40 the-job renamed-folder/the-job : total 24 lrwxr-xr-x 1 recampbell staff 1 Jun 2 15:40 1 -> 1 lrwxr-xr-x 1 recampbell staff 2 Jun 2 15:40 lastFailedBuild -> -1 lrwxr-xr-x 1 recampbell staff 1 Jun 2 15:40 lastStableBuild -> 1 lrwxr-xr-x 1 recampbell staff 1 Jun 2 15:40 lastSuccessfulBuild -> 1 lrwxr-xr-x 1 recampbell staff 2 Jun 2 15:40 lastUnstableBuild -> -1 lrwxr-xr-x 1 recampbell staff 2 Jun 2 15:40 lastUnsuccessfulBuild -> -1

          Ryan Campbell added a comment -

          On the duplicate issue JENKINS-33941, jglick said: Possibly the Job.renameTo override needs to be replaced with an ItemListener.onLocationChanged implementation.

          Ryan Campbell added a comment - On the duplicate issue  JENKINS-33941 , jglick  said: Possibly the Job.renameTo override needs to be replaced with an ItemListener.onLocationChanged implementation.

          rsandell added a comment -

          I have a feeling this is not a core issue, but an issue in folders plugin.

          Writing a test to confirm.

          rsandell added a comment - I have a feeling this is not a core issue, but an issue in folders plugin. Writing a test to confirm.

          Code changed in jenkins
          User: Robert Sandell
          Path:
          core/src/main/java/hudson/Util.java
          core/src/main/java/hudson/model/Job.java
          core/src/main/java/jenkins/model/Jenkins.java
          core/src/test/java/hudson/UtilTest.java
          test/src/test/java/hudson/model/JobTest.java
          http://jenkins-ci.org/commit/jenkins/3adfed4b06a7f525446ea80a0164a3bf2e889d1a
          Log:
          JENKINS-44657 Move sub-job's buildsdir when outside of itemrootdir (#2932)

          • JENKINS-44657 Move sub-job's buildsdir when outside of itemrootdir.

          Because we've added a test dependency that affects it.

          for tests

          • JENKINS-44657 catch InvalidPathException and rethrow as IOException

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Robert Sandell Path: core/src/main/java/hudson/Util.java core/src/main/java/hudson/model/Job.java core/src/main/java/jenkins/model/Jenkins.java core/src/test/java/hudson/UtilTest.java test/src/test/java/hudson/model/JobTest.java http://jenkins-ci.org/commit/jenkins/3adfed4b06a7f525446ea80a0164a3bf2e889d1a Log: JENKINS-44657 Move sub-job's buildsdir when outside of itemrootdir (#2932) A test to verify JENKINS-44657 is working in core JENKINS-44657 Move sub-job's buildsdir when outside of itemrootdir. JENKINS-44657 Fix UsageStatisticsTest Because we've added a test dependency that affects it. JENKINS-44657 Normalize the path before comparing JENKINS-44657 Use MockFolder instead of folders-plugin for tests JENKINS-44657 Document and annotate isDefaultBuildDir JENKINS-44657 isDescendant doesn't throw IOException any more JENKINS-44657 catch InvalidPathException and rethrow as IOException

          Daniel Beck added a comment -

          Fixed towards 2.80.

          Daniel Beck added a comment - Fixed towards 2.80.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          core/src/main/java/hudson/Util.java
          http://jenkins-ci.org/commit/jenkins/6a4d800091926c5484483f79e8936ac9d21d67a1
          Log:
          JENKINS-44657 Noting when #2932 was merged.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: core/src/main/java/hudson/Util.java http://jenkins-ci.org/commit/jenkins/6a4d800091926c5484483f79e8936ac9d21d67a1 Log: JENKINS-44657 Noting when #2932 was merged.

          Marie-Helene Touchette added a comment - - edited

          Was this fix integrated in the latest LTS release (2.89.1)?

          Because I'm still losing projects' build histories when moving a subfolder containing projects from one folder to another.  And looking on disk, I can see that build folders/files were left behind at their old location.

          (my custom build record root directory: /jenkins/jobs/${ITEM_FULL_NAME}/builds)

           

          example: if I move SubFolder2 under Folder2, all builds for Project4 and Project5 are left behind (and lost, as far as the end-user is concerned)

           

          ROOT

           |

           |–Folder1 

           |      |— SubFolder1 : Project1, Project2, Project3 

           |      |--- SubFolder2 : Project4, Project5

           |

           |--Folder2

           |

          Marie-Helene Touchette added a comment - - edited Was this fix integrated in the latest LTS release (2.89.1)? Because I'm still losing projects' build histories when moving a subfolder containing projects from one folder to another.  And looking on disk, I can see that build folders/files were left behind at their old location. (my custom build record root directory: /jenkins/jobs/${ITEM_FULL_NAME}/builds)   example: if I move SubFolder2 under Folder2, all builds for Project4 and Project5 are left behind (and lost, as far as the end-user is concerned)   ROOT  |  |–Folder1   |      |— SubFolder1 : Project1, Project2, Project3   |      |--- SubFolder2 : Project4, Project5  |  |--Folder2  |

          Daniel Beck added a comment -

          Was this fix integrated in the latest LTS release (2.89.1)?

          As the two comments preceding yours will tell you, it's in 2.80, and therefore in 2.89, and therefore in 2.89.1.

          That said,

          I'm still losing projects' build histories when moving a subfolder containing projects from one folder to another.

          I wouldn't be surprised if this was missed as it's different from the reported issue. Pinging rsandell to see whether he expects this case to be handled by his fix, or whether that's a similar but different situation.

          Daniel Beck added a comment - Was this fix integrated in the latest LTS release (2.89.1)? As the two comments preceding yours will tell you, it's in 2.80, and therefore in 2.89, and therefore in 2.89.1. That said, I'm still losing projects' build histories when moving a subfolder containing projects from one folder to another. I wouldn't be surprised if this was missed as it's different from the reported issue. Pinging rsandell to see whether he expects this case to be handled by his fix, or whether that's a similar but different situation.

          Hippo Star added a comment - - edited

          We got 2.89.2 on Linux and renaming a job when using a custom build root directory still doesn't work.

          The job name changes but the actual folder is not renamed and we lose all build history and saved artifacts.

          If anyone needs to get their files back.... the files are still there inside the folder with the previous name so one option to get your stuff back is to re-rename your job back to the previous name.

          Hippo Star added a comment - - edited We got 2.89.2 on Linux and renaming a job when using a custom build root directory still doesn't work. The job name changes but the actual folder is not renamed and we lose all build history and saved artifacts. If anyone needs to get their files back.... the files are still there inside the folder with the previous name so one option to get your stuff back is to re-rename your job back to the previous name.

          We are still facing this issue using LTS 2.107.3

          Could you point us to the LTS version which support this renaming feature without loss of history?

          BR

          Geoffroy Jabouley added a comment - We are still facing this issue using LTS 2.107.3 Could you point us to the LTS version which support this renaming feature without loss of history? BR

            rsandell rsandell
            recampbell Ryan Campbell
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: