问题
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