You can access the paths that are configured for this build through the IBuildDetails.
Just use the VersionControlServer class to query the
BranchObjects, then check which one is the root for your working
folder.
Sample Code:
IBuildDetail buildDetail = context.GetExtension<IBuildDetail>();
var workspace = buildDetail.BuildDefinition.Workspace;
var versionControlServer = buildDetail.BuildServer.TeamProjectCollection.GetService<VersionControlServer>();
var branches = versionControlServer.QueryRootBranchObjects(RecursionType.Full);
var referencedBranches = listOfFilePaths.GroupBy(
file =>
branches.SingleOrDefault(
branch => file.ServerItem.StartsWith(branch.Properties.RootItem.Item)
)
).Where(group => group.Key != null);
More details please refer jessehouwing's reply in this question: Include branch name in post build event on Team Build