3
votes

I am trying to get the "Require template" check working on a protected resource (Agent Pool, Service Connection, etc) in my Azure Pipelines.

I've got a shared template setup in a common repository (named "goldenimage-azure-pipelines-templates") that is defined as follows:

# /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 }}

Then I have a set of shared templates in the same repository that are referenced by the consuming azure-pipelines.yml file.

# /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

Now, in my consuming repository, I have the azure-pipelines.yml file defined as follows:

# 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

And then in my protected resource (Agent Pool or Service Connection), I've defined the check as follows:

Required YAML template

But whenever the build runs, it ALWAYS reports that it has failed this check.

I've tried changing the syntax for the Ref to several different options such as:

  • feature/WI443-baseTest
  • refs/heads/feature/WI443-baseTest
  • refs/tags/extend (made this tag just for this test)

I've also tried adding and removing the leading slash on the path to the template, and well as adding @templates on the end of it.

In addition, I have added and removed the template on both the Service Connection, and the Agent pool (in case it would work with one, but not the other).

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.

Build Jobs

What am I doing wrong?

1
Hi friend, is there any update for this issue? Still it can't work even with branch baseTest?LoLance

1 Answers

0
votes

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.

The direct cause of the issue is that your pipeline doesn't pass the Require Template check. I think the jobs are canceled because of that.

I found it could work well if all my resources were in branch whose format was feature. and same issue occurred if I used a branch like feature/xxx. So I think the second format branch is not supported well in Require Template check .

enter image description here

Check the pic above, according to my tests the check works well for DevBranch, but not Feature/Test. I suggest you can post a feature request here to report this issue. Thanks for your help to make our product better :)