问题
I'm using the YML file and i'm trying to set the build number format using the following snippet, but I'm not quite sure how to get the `Build.SourceBranch' into the formatting.
I've tried to use $(Build.SourceBranch) ... (Build.SourceBranch) and Build.SourceBranch
I'm attempting to set the output to look like
20190220-create-yaml.2
etc for when it's a feature feature branch.
and just 20190220.3
when it's a master branch.
variables:
${{ if ne(variables['Build.SourceBranch'], 'master') }}:
branchSuffix: ${{ format('-{0}', $(Build.SourceBranch)) }}
${{ if eq(variables['Build.SourceBranch'], 'master') }}:
branchSuffix: ''
name: $(Date:yyyyMMdd)$(branchSuffix)$(Rev:.r)
回答1:
As Lance Li mentioned, use Build.SourceBranchName
instead of Build.SourceBranch
. Additionally, in format
function use Build.SourceBranchName
variable through variables
function:
variables:
${{ if ne(variables['Build.SourceBranchName'], 'master') }}:
branchSuffix: ${{ format('-{0}', variables['Build.SourceBranchName']) }}
${{ if eq(variables['Build.SourceBranchName'], 'master') }}:
branchSuffix: ''
name: $(Date:yyyyMMdd)$(branchSuffix)$(Rev:.r)
If you want to use $(Build.SourceBranch)
, add to comparing value refs/heads
:
ne(variables['Build.SourceBranch'], 'refs/heads/master')
来源:https://stackoverflow.com/questions/60314702/setting-build-number-format-conditionally