pogorman
pogorman

Reputation: 1711

How to move Jenkins Build Record Root Directory

I am confused on how to move the "Build Record Root Directory". Right now this is my configuration: config

So on disk, for a multibranch pipline it looks like this: Workspace: Workspace

Jobs: jobs

So for my job "WindToolsService" the configuration ${ITEM_ROOTDIR}/builds results in the following path:

C:\Jenkins\jobs\WindToolsService\branches\develop\builds

Now I want to move the entire C:\Jenkins\jobs directory to a new disk, what is the correct setting to use?

We have tried the following but it didn't work, the C:\Jenkins\jobs folder was recreated when I tried a build a job.

  1. Copy the contents of “C:\Jenkins\jobs” to “E:\builds”
  2. Rename “C:\Jenkins\jobs” to “C:\Jenkins\jobs_temp” to make sure new setting works
  3. Restart Jenkins

What am I missing here?

Update

Ok - this is not really possible, at least the way I want to do it.

The original path structure is : C:\Jenkins\jobs\JOBNAME\branches\BRANCHNAME\builds but the new path is E:\builds\JOBNAME\BRANCHNAME\builds. This mean I cant just change the setting and cut and paste the contents of the jobs folder, the directory structure is different. Also the jobs folder contains other job information apart from the build records. I would be cleaner and easier just to move the entire jenkins installation

Upvotes: 2

Views: 4388

Answers (1)

Jon S
Jon S

Reputation: 16346

The jobs folder contains some other information besides the build history, for example it contains the actual job definition (more info here). Additionally the option Build Record Root Directory only affects the builds located in the job folder. So, you will need to keep the jobs folder and all the sub-folders for the jobs (but not the builds folder in all the job folders).

Apparently Jenkins expands the variables ITEM_FULL_NAME and ITEM_ROOTDIR differently. This means that it's not a simple matter of copying the jobs folder to the new location, especially when you use multibranch pipelines, matrix jobs, organisation folders or normal folders. For more info see discussion in comments

Anyway, with that in mind, here is an updated answer (old one is below):

Since it isn't straight forward as copying a folder, the folder structure needs to be transformed, this means that it is best to let Jenkins do the move. The following groovy script will move the builds folders to the correct place by expanding the different macros. The script is executed in the Script Console (Manage Jenkins -> Script Console). Change the newRootBuildsFolder to what ever location you need to move to.

newRootBuildsFolder = new File("E:\builds")

def visitJob(job) {
  if (job instanceof Job) {
    def oldBuildsFolder = job.getBuildDir()
    def newBuildsFolder = new File(newRootBuildsFolder, Jenkins.expandVariablesForDirectory('${ITEM_FULL_NAME}', job.getFullName(), job.getRootDir().getPath()))
    new FilePath(oldBuildsFolder).copyRecursiveTo("**", new FilePath(newBuildsFolder))
  }

  if (job instanceof ItemGroup) {
    for (item in job.getItems()) {
      visitJob(item)
    }
  }
}

visitJob(Jenkins.instance)
println "Done"

Please note that this may take several minutes or hours if the instance is big with loads with build history. You can monitor the progress of the script through the file system, i.e. go to the new builds folder and check which jobs has been moved.

After this script has been executed, the builds folder will need to be update in the Jenkins configuration;

  1. Go to Manage Jenkins -> Configure System and change Build Record Root Directory to E:\builds\${ITEM_FULL_NAME}\builds
  2. Restart Jenkins

OLD ANSWER:

Now, with that in mind, the following should work:

  1. Wait until no builds are ongoing, and prevent new builds from starting during the remainder of these procedures.
  2. Copy the contents of C:\jenkins\jobs to E:\builds.
  3. Go to Manage Jenkins -> Configure System and change Build Record Root Directory to E:\builds\${ITEM_FULL_NAME}\builds
  4. Restart Jenkins
  5. Start a new build and ensure that the new build information is written to the folder under E:\builds\. E.g. if we have the job X and previous build was 123, then when we start a new build for X, build 124, then the folder E:\builds\X\builds\124 should be created, and the folder C:\jenkins\jobs\X\builds\124 should not be created.

Later on, when you see that all is working when, then you can delete the old builds folders under C:\jenkins\jobs\**\.

Upvotes: 4

Related Questions