How to automate migrating repositories in Bamboo build plans

How to automate migrating repositories in Bamboo build plans

Description

Suppose you have 10s or 100s of build plans and you want to update the plan's repository to use a different repository. What a pain to do this manually! You have to go into each plan and configure the new repository, remove the old and remember to select the option to replace references to the old repository with the new repository. We recently used the techniques described here to support migrating repositories that impacted 100's of build plans across 4 Bamboo systems. 

This article describes how this can be done in minutes with automation using Bamboo CLI 7.2. There are a number of use cases that force this kind of migration:

  1. Switching repository types like Mercurial to Git or similar. 

  2. Switching repository providers like GitHub, Bitbucket, or Bitbucket Server

The techniques described here can be used in general to report on where used information for repositories. Just use step 3 below.

Steps

Step

Action

Step

Action

1

Pause server

Optional, but recommended to reduce risk of Bamboo getting confused. Use pauseServer or do it from the UI.

2

If you want reuse the same repository name

Rename the old repository. Do this from the UI.

3

Add new linked repository

Easy enough to do this via the UI as well. Or use your standard addRepository action as you have already automated that.
-a addRepository ...

4

Find all the plans using the old repository

Optional. This is just to check to see what plans are impacted.
-a getPlanList --project @all --options "usingRepository=oldName" 

5

Add a reference to the linked repository in each plan

-a runFromPlanList --project @all --options "usingRepository=oldName" --common "-a addRepository --plan @plan@ --repository newName --continue"

6

Remove the old repository from each plan

-a runFromPlanList --project @all --options "usingRepository=oldName" --common "-a removeRepository --plan @plan@ --repository oldName --options replaceRepository=newName"

7

Resume server

If you paused the server for this activity, remember to use resumeServer or the UI to resume normal build processing.