git teamcity中的Git短分支名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20514112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git short branch name in teamcity
提问by ?mer Faruk Aplak
I'm using teamcity 8.x.x version.I configured my Teamcity for continuous deployment. I'm need a feature branching deployment. I see this document "http://confluence.jetbrains.com/display/TCD8/Working+with+Feature+Branches".
我使用的是 teamcity 8.xx 版本。我配置了我的 Teamcity 以进行持续部署。我需要一个功能分支部署。我看到这个文件“ http://confluence.jetbrains.com/display/TCD8/Working+with+Feature+Branches”。
I'm trying this document implementing on my Teamcity. I have a problem.
我正在尝试在我的 Teamcity 上实施此文档。我有个问题。
My deployment config use "OctoPack" (nuget). My nuget package needs build count and branch name. example: 1.0.0.356-feature-1.
我的部署配置使用“OctoPack”(nuget)。我的 nuget 包需要构建计数和分支名称。例如:1.0.0.356-feature-1。
I'm try this versioning,
我正在尝试这种版本控制,
%build.number%-%teamcity.build.vcs.branch.VCS_ROOT_ID% ----> 1.0.0.356-refs/head/feature-1
%build.number%-%teamcity.build.vcs.branch.VCS_ROOT_ID% ----> 1.0.0.356-refs/head/feature-1
this version not support nuget versioning. nuget not comparative "/".
此版本不支持 nuget 版本控制。nuget 不是比较“/”。
I need this,
我需要这个,
%build.number%-%teamcity.build.vcs.SHORT_BRANCH_NAME.VCS_ROOT_ID% ---> 1.0.0.356-feature-1
%build.number%-%teamcity.build.vcs.SHORT_BRANCH_NAME.VCS_ROOT_ID% ---> 1.0.0.356-feature-1
how can I ?
我怎样才能 ?
Thanks
谢谢
采纳答案by Pedro Pombeiro
I believe what you need is another variable. Try using %vcsroot.branch%. There is also %teamcity.build.branch%, but that one will contain "<default>" on the default branch. If you want more flexibility to choose exactly which part of the branch name gets selected, you can follow the instructions on this page:
我相信你需要的是另一个变量。尝试使用%vcsroot.branch%。还有%teamcity.build.branch%,但那个将在默认分支上包含“ <default>”。如果您想要更灵活地选择确切选择分支名称的哪一部分,您可以按照此页面上的说明进行操作:
回答by soniiic
I found that if you have one branch set up in the VCS, then %teamcity.build.branch%
is not defined. And if you have multiple branches defined, then %vcsroot.branch%
only reports on the the name of the default branch.
我发现如果您在 VCS 中设置了一个分支,则%teamcity.build.branch%
未定义。如果定义了多个分支,%vcsroot.branch%
则只报告默认分支的名称。
I ended up using a git command to give the current branch name.
我最终使用了一个 git 命令来给出当前的分支名称。
Powershell:
电源外壳:
$branch = (git symbolic-ref --short HEAD) | Out-String
$branch = (git symbolic-ref --short HEAD) | Out-String
Command Line:
命令行:
FOR /F "tokens=* USEBACKQ" %%%%F IN (`git symbolic-ref --short HEAD`) DO (
SET branchName=%%%%F
)
ECHO %%branchName%%
TeamCity converts all %% -> % so that's why there are so many %
TeamCity 转换了所有 %% -> % 所以这就是为什么有这么多 %
Set as environment variable
设置为环境变量
If you would like to use the branch name as an environment variable to be used in other steps of your project you can set the branch name by using Powershell as an example. First define env.currentBranch in your build configuration and then set it with the following powershell as your first build step.
如果您想将分支名称用作项目其他步骤中使用的环境变量,您可以以 Powershell 为例设置分支名称。首先在您的构建配置中定义 env.currentBranch,然后使用以下 powershell 将其设置为您的第一个构建步骤。
$branch = (git symbolic-ref --short HEAD) | Out-String
Write-Host "##teamcity[setParameter name='env.currentBranch' value='$branch']"