Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a single TFS 2010 build definition be used for multiple branches?

Tags:

build

msbuild

I look after builds of our products and have been asked to come up with a way of customising an existing build definition to build different branches when required.

The build process for this product has several custom steps and actions already and the product has a large amount of project files that are built so its not effective to set up a new build definition for every new branch that is created.

The build definition is set up to build from the Main branch. The aim is to enter a particular branch (using a workflow argument that can be entered when a build is queued) which will then be built instead of the default Main branch without having to edit the build definition.

I have a separate test program that I use for testing all my custom build activities and procedures on. In the workflow for this build definition, I have added a fair few build messages for logging purposes so that I can view the values of variables used in the build process.

I have also created a branch based on this test program ready for testing of a build definition that can be used to build more than one branch

first off, I ran a build for the original test solution's project files from the original branch, then changed the build definition so that the same would be done using the new branch and ran another build. When comparing the build logs between the 2 branches there are only a few minor differences between them. (Logging Verbosity set to Diagnostic)

1st difference - I looked a the Workspace variable and the Folders property of the builds reference their respective branches, specifically the ServerItem property of the Folders property

2nd difference - The project files being built (BuildSettings.ProjectsToBuild) are coming from the respective branches

I haven't seen any other differences between the 2 build logs other than these

The main question here:

Is there a standard way of swapping the branches being built for a single build definition?

If not, would it be possible to simply change all references to the default Main branch in the customised workflow template (in Workspace and BuildSettings.ProjectsToBuild) to the entered branch when queueing a build?

As always, thanks in advance for any and all help

like image 286
Vermin Avatar asked Oct 06 '11 07:10

Vermin


1 Answers

I have managed to amend my build's workflow template so that builds for multiple branches of the solution are possible. To achieve this I had to change certain things within the workflow and also create some extra workspaces for the service account that run the builds.

  1. I added an argument to the workflow so that the required branch can be entered when the build is queued.

  2. I changed the drop location for the build so that it is relevant for the entered branch (optional)

  3. Created a separate sources directory on the build machine for the branch build

  4. Initialised the WorkspaceName and SourcesDirectory so that they match the new workspace name and sources directory folder

  5. I created a custom activity to change the list of projects/solutions in BuildSettings.ProjectsToBuild so that they were referencing them from the entered branch

  6. I noticed through my testing phase that even though my new workspace for the entered branch was initially set up to use the entered branch as its ServerItem, it would still create the workspace with the ServerItem that was entered in the build definition. To get around this, I created another custom activity to remap the branch workspace so that the ServerItem was pointing to the correct branch

There are a few other things that I have involved in my workflow, but they are more tweaks that my developers have requested, the above steps have resulted in multiple branch builds for a single build definition.

like image 93
Vermin Avatar answered Oct 02 '22 15:10

Vermin