Setting build number format conditionally

筅森魡賤 提交于 2021-02-11 18:18:13

问题


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

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