【问题标题】:setting up name in extend template doesn't work in azure yaml pipelines在扩展模板中设置名称在 azure yaml 管道中不起作用
【发布时间】:2020-07-27 21:15:03
【问题描述】:

这是开发者回购管道

resources:
  repositories:
  - repository: extendCheck
    type: git
    name: PUL/extendCheck

trigger:
- none

extends:
  template: base2.yml@extendCheck
  parameters:
    buildSteps:  
      - bash: echo Test #Passes
        displayName: succeed
      - bash: echo "Test"
        displayName: succeed
      - script: echo "Script Test" 
        displayName: Fail

这是来自集中策略团队回购的扩展模板

# File: start.yml
name: $(Date:yyyy)$(Date:.MM)$(Date:.dd)$(Rev:-r)
parameters:
- name: buildSteps # the name of the parameter is buildSteps
  type: stepList # data type is StepList
  default: [] # default value of buildSteps
stages:
- stage: secure_buildstage
  pool:
    vmImage: 'ubuntu-latest'
  jobs:
  - job: secure_buildjob
    steps:

    - script: echo This happens before code 
      displayName: 'Base: Pre-build'

    - script: echo Building
      displayName: 'Base: Build'

    - ${{ each step in parameters.buildSteps }}:
      - ${{ each pair in step }}:
          ${{ if ne(pair.key, 'script') }}:
            ${{ pair.key }}: ${{ pair.value }}       
          ${{ if eq(pair.key, 'script') }}: # checks for buildStep with script
            'Rejecting Script: ${{ pair.value }}': error # rejects buildStep when script is found         

    - script: echo This happens after code
      displayName: 'Base: Signing'

当我运行它时,我得到以下错误

/base2.yml@extendCheck (Line: 2, Col: 1): Unexpected value 'name'

我们希望控制内部版本号格式,因此不想将其保留在开发者存储库中。 对此问题的任何建议

【问题讨论】:

    标签: azure-devops azure-pipelines azure-pipelines-yaml


    【解决方案1】:

    很遗憾,不支持使用name 的模板。要解决此问题,我们可以使用脚本定义变量并使用UpdateBuildNumber command 更新构建编号格式。例如,在base2.yml文件末尾添加如下任务:

    - task: PowerShell@2
      inputs:
        targetType: 'inline'
        script: |
          [string] $dateTime = (Get-Date -Format 'yyyyMMddTHHmmss')
          Write-Host "##vso[task.setvariable variable=name]$dateTime"  
    - script: echo "##vso[build.updatebuildnumber]$(name)"
    

    【讨论】:

    • 如何在 powershell 中使用这个 $(Date:yyyy)$(Date:.MM)$(Date:.dd)$(Rev:-r) 作为格式?
    • 特别是 (Rev:-r) ,在扩展模板中使用它的目的是确保我们不使用用户指定的名称,而是使用上述格式生成标准构建名称。如果他们在他们的 repo 中更新名称,则修订值会有所不同。
    • 在 Azure DevOps 中,Rev 是一种特殊的变量格式,仅适用于内部版本号字段。您可以改用 $(Build.BuildNumber)counter() 表达式。在此处查看博客:andrewhoefling.com/Blog/Post/…
    猜你喜欢
    • 2020-10-05
    • 2021-03-01
    • 2021-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多