标记VSTS关于分支名称的构建 [英] tag VSTS build regarding branch name

查看:191
本文介绍了标记VSTS关于分支名称的构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用了VSTS for CD / CI,并且我喜欢根据git分支名称来标记我的构建(而不是git分支)。下面是标记VSTS构建的PowerShell脚本(它与git标签不同)

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

如果($(Build.SourceBranchName) - 例如deploy / dev *)
{Write-Host## vso [build.addbuildtag] dev}

所以当我的代码分支(git)是master时,它应该标记为prod
,这样做很好。



但是当我的分支名称与deploy / dev / feature1类似时,它应该标记为dev,但它不会出错!



有什么想法?

解决方案

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

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

如果($(Build.SourceBranch)-likerefs / heads / deploy / dev *)
{Write-Host## vso [build.addbuildtag] dev}


I'm using VSTS for CD/CI and I like to tag my builds (not the git branch) based on the git branch name.

I got the below PowerShell script which is tagging the VSTS builds (it's different o git tag) :

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

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

so when my code branch (git) is "master" then it's supposed to tag it "prod" which is does just fine.

but when my branch name is something like "deploy/dev/feature1", it's supposed to tag it "dev" which it doesn't, it also doesn't error!

any idea?

解决方案

I just found out what is the problem, this variable only return the branch name without prefix e.g. deploy/dev/feature1 so the solution would be to use something else that gives us the full branch name which is here:

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"}

这篇关于标记VSTS关于分支名称的构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆