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

When 'Build Record Root Directory' is enabled, renaming a job does not create a new BRRD dir for the renamed job, and does not rename/copy artifacts from the original BRRD

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Duplicate
    • Component/s: core
    • Labels:
      None
    • Similar Issues:

      Description

      We have a Jenkins instance (1.438) using the 'Build Record Root Directory' feature, so we can specify an alternate directory for storing build artifacts outside of the JENKINS HOME directory.

      The 'Build Record Root Directory' (set in configure system, then click Advanced... button at the top), is set to /scratch/jbuildroot/${ITEM_FULLNAME}/builds. The Workspace Root dir is set to ${ITEM_ROOTDIR}/workspace.

      This generally works fine. However, I noticed that when I rename a job, I lose the previous build records.

      I see a new build record directory is created, beneath the specified 'Build Record Root Directory'. However, the old build directory also exists, containing the previous records. They are not moved over to the new directory.

      In other words, when the 'Build Record Root Directory' feature is enabled, renaming a project causes the project's build records to be lost.

      Current workaround is to move the build record files over and use sed to replace the project name in them, then restart Jenkins.

        Attachments

          Issue Links

            Activity

            Hide
            sroth Steve Roth added a comment -

            This is still an issue in Jenkins 1.450

            Show
            sroth Steve Roth added a comment - This is still an issue in Jenkins 1.450
            Hide
            sroth Steve Roth added a comment -

            I was able to reproduce using a vanilla OOTB Jenkins install.

            Steps to repro:
            1- Install Jenkins
            2- Go to Manage / Configure page, click Advanced... button at top of screen, set Build Record Root Directory to /scratch/jbuildroot/${ITEM_FULLNAME}/builds or something like that, click Save
            3- Create a test job with a shell script section, do a few runs, note the logs are saved to /scratch/jbuildroot/JOBNAME/builds
            4- Rename the test job. Note there is a new dir at /scratch/jbuildroot/NEWJOBNAME/builds but it has one empty run. The old runs are still under /scratch/jbuildroot/JOBNAME/builds
            5- Restart Jenkins via yourhost:8080/restart
            6- Note the test job runs are gone because the Build Records were not moved to the new dir.

            Show
            sroth Steve Roth added a comment - I was able to reproduce using a vanilla OOTB Jenkins install. Steps to repro: 1- Install Jenkins 2- Go to Manage / Configure page, click Advanced... button at top of screen, set Build Record Root Directory to /scratch/jbuildroot/${ITEM_FULLNAME}/builds or something like that, click Save 3- Create a test job with a shell script section, do a few runs, note the logs are saved to /scratch/jbuildroot/JOBNAME/builds 4- Rename the test job. Note there is a new dir at /scratch/jbuildroot/NEWJOBNAME/builds but it has one empty run. The old runs are still under /scratch/jbuildroot/JOBNAME/builds 5- Restart Jenkins via yourhost:8080/restart 6- Note the test job runs are gone because the Build Records were not moved to the new dir.
            Hide
            sroth Steve Roth added a comment - - edited

            One shell script workaround for renaming the fileystem parts of job (presumes a path like ${ITEM_FULLNAME}/builds is listed below. Save as 'renamejob.sh'.

            First, backup your original job name directory, just in case.
            Next, rename the job in the Jenkins UI.
            Then run this script
            Last, restart Jenkins (required).

            Usage: renameJob.sh pathToBuildArtifactDir oldJobName newJobName

            #!/bin/sh -eu
            
            JOBROOT=$1
            OLDJOB=$2
            NEWJOB=$3
            
            if [ ! -d $JOBROOT ]; then
            echo "ERROR: directory at JOBROOT=$JOBROOT does not exist"
            exit 1
            fi
            
            if [ ! -d $JOBROOT/$NEWJOB ]; then
              mkdir -p $JOBROOT/$NEWJOB
            #echo "ERROR: newjob directory at $JOBROOT/$NEWJOB does not exist"
            #exit 1
            fi
            
            if [ ! -d $JOBROOT/$OLDJOB ]; then
            echo "ERROR: oldjob directory at $JOBROOT/$OLDJOB does not exist"
            exit 1
            fi
            
            echo "RENAMING JOB from $OLDJOB ==> $NEWJOB"
            set +e
            rm -rf $JOBROOT/$NEWJOB/builds/*
            mv $JOBROOT/$OLDJOB/* $JOBROOT/$NEWJOB
            set -e
            
            echo "RENAMING OLD JOB TO END IN .old"
            set +e
            mv $JOBROOT/$OLDJOB $JOBROOT/${OLDJOB}.old
            set -e
            
            echo "UPDATING RUNS..."
            for RUNDIR in `ls -d $JOBROOT/$NEWJOB/builds/2012*`; do
            echo "... UPDATING RUN AT $RUNDIR"
            if [ -f $JOBROOT/$RUNDIR/junitResult.xml ]; then
            sed -i "s/$OLDJOB/$NEWJOB/g" $JOBROOT/$RUNDIR/junitResult.xml
            fi
            if [ -f $JOBROOT/$RUNDIR/build.xml ]; then
            sed -i "s/$OLDJOB/$NEWJOB/g" $JOBROOT/$RUNDIR/build.xml
            fi
            done
            
            echo "REMOVING .old JOB (this may fail if more work is needed)"
            rmdir $JOBROOT/${OLDJOB}.old
            
            Show
            sroth Steve Roth added a comment - - edited One shell script workaround for renaming the fileystem parts of job (presumes a path like ${ITEM_FULLNAME}/builds is listed below. Save as 'renamejob.sh'. First, backup your original job name directory, just in case. Next, rename the job in the Jenkins UI. Then run this script Last, restart Jenkins (required). Usage: renameJob.sh pathToBuildArtifactDir oldJobName newJobName #!/bin/sh -eu JOBROOT=$1 OLDJOB=$2 NEWJOB=$3 if [ ! -d $JOBROOT ]; then echo "ERROR: directory at JOBROOT=$JOBROOT does not exist" exit 1 fi if [ ! -d $JOBROOT/$NEWJOB ]; then mkdir -p $JOBROOT/$NEWJOB #echo "ERROR: newjob directory at $JOBROOT/$NEWJOB does not exist" #exit 1 fi if [ ! -d $JOBROOT/$OLDJOB ]; then echo "ERROR: oldjob directory at $JOBROOT/$OLDJOB does not exist" exit 1 fi echo "RENAMING JOB from $OLDJOB ==> $NEWJOB" set +e rm -rf $JOBROOT/$NEWJOB/builds/* mv $JOBROOT/$OLDJOB/* $JOBROOT/$NEWJOB set -e echo "RENAMING OLD JOB TO END IN .old" set +e mv $JOBROOT/$OLDJOB $JOBROOT/${OLDJOB}.old set -e echo "UPDATING RUNS..." for RUNDIR in `ls -d $JOBROOT/$NEWJOB/builds/2012*`; do echo "... UPDATING RUN AT $RUNDIR" if [ -f $JOBROOT/$RUNDIR/junitResult.xml ]; then sed -i "s/$OLDJOB/$NEWJOB/g" $JOBROOT/$RUNDIR/junitResult.xml fi if [ -f $JOBROOT/$RUNDIR/build.xml ]; then sed -i "s/$OLDJOB/$NEWJOB/g" $JOBROOT/$RUNDIR/build.xml fi done echo "REMOVING .old JOB ( this may fail if more work is needed)" rmdir $JOBROOT/${OLDJOB}.old
            Hide
            sroth Steve Roth added a comment -

            This is still an issue with Jenkins v1.454.

            Show
            sroth Steve Roth added a comment - This is still an issue with Jenkins v1.454.
            Hide
            sroth Steve Roth added a comment -

            I noticed that in Jenkins v1.454, renaming a job does not even create the build record root dir entry. For example, if I have build record root dir set to /scratch/jbuildroot/${ITEM_FULLNAME}/builds and I rename a job 'foo' to 'bar', then /scratch/jbuildroot/foo exists, but the rename does not create /scratch/jbuildroot/bar.

            I think in a previous version, this directory was at least created (though it was empty), but in v1.454, I dont see it created anymore.

            Updating the summary to reflect the new information.

            Show
            sroth Steve Roth added a comment - I noticed that in Jenkins v1.454, renaming a job does not even create the build record root dir entry. For example, if I have build record root dir set to /scratch/jbuildroot/${ITEM_FULLNAME}/builds and I rename a job 'foo' to 'bar', then /scratch/jbuildroot/foo exists, but the rename does not create /scratch/jbuildroot/bar. I think in a previous version, this directory was at least created (though it was empty), but in v1.454, I dont see it created anymore. Updating the summary to reflect the new information.
            Hide
            danielbeck Daniel Beck added a comment -

            Duplicates JENKINS-17138 (it was resolved using that issue ID)

            Show
            danielbeck Daniel Beck added a comment - Duplicates JENKINS-17138 (it was resolved using that issue ID)

              People

              • Assignee:
                Unassigned
                Reporter:
                sroth Steve Roth
              • Votes:
                2 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: