tfs - Include branch name in post build event on Team Build -
i perform following steps in tfs build process:
- do post build event copy files compiled projects predefined directory, i'd directory path include branch name.
- i'd able refer branch name inside xaml workflow template well.
the first 1 rather simple. when you're using new tfs 2013 build server , process template, can add post-build powershell script in build definition configuration, check in script , run during build.
the second 1 dependent on whether you're using tfvc or git, in first case, use versioncontrolserver class query branchobjects, check 1 root working folder. aware though, in tfvc multiple branches can referenced in 1 workspace, there may multiple answers query, depending on file use find branchroot. custom codeactivity trick, similar this check in custom checkin policy.
the code similar to:
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);
to list of items in yo workspace, can use workspace.getitems
.
in case you're using git, have few options well. simplest invoke command line:
git symbolic-ref --short head
or dive libgit2sharp , use find branch name based on current working folder custom activity.
if want include in msbuild task, may possible well. goes bit far answer outline steps required, it's not hard once know do.
create custom msbuild task invokes same snippet of code above, though instead of getting access workspace through builddetail.builddefinition.workspace
, through workstation
class:
workstation workstation = workstation.current; workspaceinfo info = workstation.getlocalworkspaceinfo(path); tfsteamprojectcollection collection = new tfsteamprojectcollection(info.serveruri); workspace workspace = info.getworkspace(collection); versioncontrolserver versioncontrolserver = collection.getservice<versioncontrolserver>();
once task has been created, can create custom .targets
file hooks msbuild process overriding variables or copying data when build finished. can hook multiple targets , define whether need before or after them.
you can either <import>
these each of projects, or can place in importafter
or importbefore
folder of msbuild version make load globally. can find folder here:
c:\program files (x86)\msbuild\{msbuild version}\microsoft.common.targets\importafter
Comments
Post a Comment