标记有关分支名称

时间:2018-03-12 09:05:07

标签: git powershell build tags azure-devops

我使用VSTS进行CD / CI,我喜欢根据git分支名称标记我的构建(而不是git分支)。

我得到了以下PowerShell脚本,它标记了VSTS版本(它与git标签不同) :

If ("$(Build.SourceBranchName)" -like "master")
{Write-Host "##vso[build.addbuildtag]prod"}

If ("$(Build.SourceBranchName)" -like "deploy/dev*")
{Write-Host "##vso[build.addbuildtag]dev"}

所以当我的代码分支(git)是" master"然后它应该标记它" prod" 这很好。

但是当我的分支名称类似于" deploy / dev / feature1"时,它应该标记它" dev"它没有,它也没有错误!

任何想法?

1 个答案:

答案 0 :(得分:0)

我刚刚发现问题是什么,这个变量只返回没有前缀的分支名称,例如部署的/ dev /优点1 所以解决方案是使用其他东西给我们提供完整的分支名称:

If ("$(Build.SourceBranch)" -like "refs/heads/master")
{Write-Host "##vso[build.addbuildtag]prod"}

If ("$(Build.SourceBranch)" -like "refs/heads/deploy/dev*")
{Write-Host "##vso[build.addbuildtag]dev"}