Azure Pipelines "Require Template"检查不起作用

标签 azure templates azure-devops azure-pipelines

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

我在公共(public)存储库(名为“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 }}

然后,我在同一存储库中有一组共享模板,由使用的 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

现在,在我的消费存储库中,我的 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

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

Required YAML template

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

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

  • 功能/WI443-baseTest
  • refs/heads/feature/WI443-baseTest
  • refs/tags/extend(仅为本次测试创建此标签)

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

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

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

Build Jobs

我做错了什么?

最佳答案

No matter what I do, it reports that the run is not extending the template. However, I can see in the pipeline the jobs from the template, so it's obviously pulling it.

问题的直接原因是您的管道未通过需要模板检查。我认为工作岗位因此而被取消。

我发现如果我的所有资源都在格式为 feature 的分支中,它可以很好地工作。如果我使用像 feature/xxx 这样的分支,也会出现同样的问题。因此,我认为在 Require Template 检查中,第二个格式分支没有得到很好的支持

enter image description here

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

关于Azure Pipelines "Require Template"检查不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61128636/

相关文章:

c# - Azure 引用了错误的 DLL

azure - 将 Azure AppServices 中的 Web API 的访问限制为 Azure Function 应用程序,同时允许其他服务访问其他 Web api 和网页

c++ - 可互换使用的类型和非类型模板参数

git - 如何镜像Github和VS Online?

azure - 在 DevOps 中删除 Azure Analysis Services 防火墙规则

c# - 获取角色 - Azure API 返回 (400) 错误请求

powershell - 如何使用powershell部署到Azure?

c++ - std::function 类似委托(delegate)模板类

c++ - T和T&的区别?

azure - '在类型 'type' 的对象上找不到成员 'PolicyParameter'