Azure Pipelines“需要模板”检查不起作用

Ama*_*son 5 templates azure azure-devops azure-pipelines

我正在尝试对 Azure Pipelines 中的受保护资源(代理池、服务连接等)进行“需要模板”检查。

我在公共存储库(名为“goldenimage-azure-pipelines-templates”)中有一个共享模板设置,定义如下:

# /templates/pipelines/master.yml
parameters:
- name: templates
  type: object
  default: []

stages:
- ${{ each template in parameters.templates }}:
  - ${{ each pair in template }}:
      ${{ if eq(pair.key, 'template') }}:
        ${{ template }}
Run Code Online (Sandbox Code Playgroud)

然后,我在同一存储库中有一组共享模板,由使用的 azure-pipelines.yml 文件引用。

# /templates/stages/main.yml
stages:
  - stage: mainBuild
    jobs:
      - template: /templates/jobs/set-version.yml
      - template: /templates/jobs/build-image.yml
      - template: /templates/jobs/cleanup-build.yml
      - template: /templates/jobs/test-image.yml
      - template: /templates/jobs/cleanup-test.yml
      - template: /templates/jobs/update-configmap.yml
      - template: /templates/jobs/destroy-template.yml
      - template: /templates/jobs/cleanup.yml
Run Code Online (Sandbox Code Playgroud)

现在,在我的消费存储库中,我的 azure-pipelines.yml 文件定义如下:

# azure-pipelines.yml
name: $(GitVersion.NuGetVersionV2).$(Build.BuildId)

trigger:
  branches:
    include:
      - master
  paths:
    exclude:
      - 'README.md'

resources:
  repositories:
    - repository: templates
      type: git
      name: goldenimage-azure-pipelines-templates
      ref: feature/WI443-baseTest

variables:
  - template: /templates/vars/main.yml@templates
  - template: /azure-pipelines/vars.yml


extends:
  template: templates/pipelines/master.yml@templates
  parameters:
    templates:
      - template: /templates/stages/main.yml

Run Code Online (Sandbox Code Playgroud)

然后在我的受保护资源(代理池或服务连接)中,我定义了检查,如下所示:

所需的 YAML 模板

但每当构建运行时,它总是报告它未通过此检查。

我尝试将 Ref 的语法更改为几个不同的选项,例如:

  • 功能/WI443-baseTest
  • 参考文献/头/功能/WI443-baseTest
  • refs/tags/extend (为此测试创建此标签)

我还尝试添加和删除模板路径上的前导斜杠,以及@templates在其末尾添加。

此外,我还添加和删除了服务连接和代理池上的模板(以防它适用于其中一个,但不适用于另一个)。

无论我做什么,它都会报告运行没有扩展模板。但是,我可以在管道中看到模板中的作业,因此显然正在拉动它。

建立工作岗位

我究竟做错了什么?

Lan*_*SFT 0

无论我做什么,它都会报告运行没有扩展模板。但是,我可以在管道中看到模板中的作业,因此显然正在拉动它。

问题的直接原因是你的管道没有通过检查Require Template。我认为工作岗位因此而被取消。

我发现如果我的所有资源都在格式为 的分支中,它可以很好地工作feature。如果我使用像feature/xxx. 所以我认为 check中第二种格式分支没有得到很好的支持Require Template

在此输入图像描述

检查上面的图片,根据我的测试,该检查适用于DevBranch,但不适用于Feature/Test我建议您可以在此处发布功能请求来报告此问题。感谢您帮助我们改进我们的产品:)