tag VSTS build regarding branch name

眉间皱痕 提交于 2020-01-03 05:19:12

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/49231440/tag-vsts-build-regarding-branch-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!