Anson Tan
Anson Tan

Reputation: 1246

How to call Azure pipeline template that included "resources"?

For some reasons, I want my A.yml calling another B.yml from others repository. Pipeline A is consider an 'empty' pipeline, its job is basically calling pipeline B, and B done the real job. But B is not just steps, it contain all the details, it included 'Resources' also.

This is how I do:

Pipeline A:

trigger:
- main

resources:
  repositories:
  - repository: script
    type: github
    name: xxx/script
    ref: refs/heads/main
    endpoint: smartracks

steps: **<---- What should I put ?**
 - template: B.yml@script

Pipeline B:

resources:
  repositories:
  - repository: rcu-service
    type: github
    name: abc/rcu-service
    ref: refs/heads/main
    endpoint: test
jobs:
    - job: OpenEmbedded_Build_And_Export
steps:
    - checkout: rcu-service
- script: |
    ......

If I excluded the "resources" in pipeline B, it will success (need add those resources into pipeline A). But once I included resource in pipeline B, it fails with these message:

B.yml@script(Line: 1, Col: 1): Unexpected value 'resource'
B.yml@script(Line: 24, Col: 1): Unexpected value 'jobs'

In Pipeline A, this is how I call the pipeline B, I use steps, but it seems doesn't work.

  steps: **<---- What should I put ?**
     - template: B.yml@script

I try with stages, jobs, but fail too.

So, I am wonder what should I do ? Please teach me, thank you.

Upvotes: 1

Views: 1704

Answers (2)

Cece Dong - MSFT
Cece Dong - MSFT

Reputation: 31083

Azure Pipelines supports four kinds of templates:

  • Stage
  • Job
  • Step
  • Variable

It doesn't support resources, you need to put the resources in your A.yml.

https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema#template-references

Upvotes: 1

WaitingForGuacamole
WaitingForGuacamole

Reputation: 4301

Imagine that you were to expand the template so that it showed up in the file where you placed - template:.... In this case, you would have

steps:
 - jobs:
   ...

This doesn't work, because the schema requires steps to be a part of a job.

jobs: 
  - template: B.yml@script

or

stages:
- stage: stageName
  displayName: "my stage"
  jobs:
  - template: B.yml@script

Upvotes: 0

Related Questions