[ 
https://issues.jenkins-ci.org/browse/JENKINS-11716?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=158929#comment-158929
 ] 

Steve Roth edited comment on JENKINS-11716 at 4/21/12 9:21 PM:
---------------------------------------------------------------

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

{code}
#!/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
{code}
                
      was (Author: sroth):
    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 oldJobName newJobName pathToBuildArtifactDir

#!/bin/sh -eu

OLDJOB=$1
NEWJOB=$2
JOBROOT=$3

if [ ! -d $JOBROOT ]; then
   echo "ERROR: directory at JOBROOT=$JOBROOT does not exist"
   exit 1
fi

if [ ! -d $JOBROOT/$NEWJOB ]; then
   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 -f $JOBROOT/last*
rm -rf $JOBROOT/$NEWJOB/builds/*
mv $JOBROOT/$OLDJOB/* $JOBROOT/$NEWJOB
set -e

echo "UPDATING RUNS..."
for RUNDIR in `ls -d $JOBROOT/$NEWJOB/builds/*-*-*`; 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

                  
> 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
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: JENKINS-11716
>                 URL: https://issues.jenkins-ci.org/browse/JENKINS-11716
>             Project: Jenkins
>          Issue Type: Bug
>          Components: core
>    Affects Versions: current
>            Reporter: Steve Roth
>
> 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.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.jenkins-ci.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to