1

Is there a way to dynamically specify the branch name in a step with the build definition in TFS2015 (not old XAMLs)? For example I would like to specify a parameter to an MSBuild step using a variable containing the branch name: https://i.stack.imgur.com/P8Nis.png

The project to build here should be something like: $Datawarehouse\$(BranchParameter)\Project\Project.sln

and I want to specify the parameter $(BranchParameter) at running time.

2 Answers2

0

No such option to specify the parameter $(BranchParameter) at running time by default. TFS get the repository which is specified in mappings on the Repository tab. enter image description here

However, you can write your own script and add a PowerShell task to get sources that you want.

Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39
  • I don't need to create a new branch, I already have a new branch and I just want to execute the standard build on that branch rather than the main one, without adding a build definition every time! – Francesco Pizzolon Jun 20 '16 at 14:06
  • No such option to specify the parameter $(BranchParameter) at running time by default. TFS get the repository which is specified in mappings on the Repository tab. However, you can write your own script to get sources that you want. – Cece Dong - MSFT Jun 21 '16 at 09:50
  • So I will still download the code specified in the Repository Tab, but I can write my PowerShell script to get source code from another branch? can you give me an example of that script? – Francesco Pizzolon Jun 21 '16 at 15:49
  • You may check this case: http://stackoverflow.com/questions/23739499/copy-files-from-tfs-versioncontrol-to-directory-with-powershell, or use REST API: https://www.visualstudio.com/en-us/docs/integrate/api/tfvc/items#getafile – Cece Dong - MSFT Jun 22 '16 at 09:25
0

we can have branch name as a parameter and pass the branch name while triggering a build in VS. 1. Create an Argument "Branch Name" , Add in metadata and make it "Always Show the parameter" 2. Modify the "Pull sources from Git repo" activity with branch name parameter 3. Save the template and commit the changes 4. Edit build definition and select the modified template.

While queue a build you can find the BranchName parameter and pass the branch name and trigger a build.

Instead of having different build definition for each branch. you can have one build definition and pass branch name every time you trigger a build.

Hope this helps.

Thanks,

$hree