0

I have a pipeline that has a section like this that lists the pipelines that would trigger the pipeline.

resources:
  # List all the microservice pipelines to be watched plus infrastructure, the pipeline name is the name
  # of the stack.  Note template-maven and template-gradle are not to be part of this build.
  pipelines:
    - pipeline: auth
      project: services
      source: auth
      branch: master
      trigger:
        branches:
          include:
            - master
    - pipeline: ai
      project: services
      source: artificial-intelligence
      branch: master
      trigger:
        branches:
          include:
            - master
    - pipeline: ui
      project: frontend
      source: ui CI
      branch: master
      trigger:
        branches:
          include:
            - master

I then have a job with the following steps (because deployment pulls all files, I just need one folder from each pipeline

      - job: publishDeploymentPipelineFiles
        condition: not(canceled())
        steps:
          - checkout: none
          - download: auth
            artifact: drop
          - download: ai
            artifact: drop
          - download: ui
            artifact: drop

What I am hoping for is some form of template that does

  steps:
    - checkout: none
    - template: pull-deployment-manifests.yml
      parameters:
        sources:
        - project: services
          source: auth
          stackName: auth
        - project: services
          source: artificial-intelligence
          stackName: ai
        - project: frontend
          source: ui CI
          stackName: ui

Which only lists the project and CI pipeline and create the appropriate pipeline ID from stackName and create the resources and the steps.

My workaround right now is to create a project that takes a CSV containing those items and generating the azure-pipelines.yml

Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265

2 Answers2

1

As far as I know you can't dynamically create resources. So you create this

  steps:
    - checkout: none
    - template: pull-deployment-manifests.yml
      parameters:
        sources:
        - project: services
          source: auth
          stackName: auth
        - project: services
          source: artificial-intelligence
          stackName: ai
        - project: frontend
          source: ui CI
          stackName: ui

and run checkout inside the template unless you defined resources with those names on root level.

As documentation says here:

Resources are defined at one place and can be consumed anywhere in your pipeline.

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
  • Interesting though won't work for me because my `resources` are `pipelines` and I want my pipeline triggered from those pipelines. Will accept yours for now since it indicates it cannot be done. If I or someone writes out the workaround of chaining pipelines (which I wanted to avoid) I'll accept that one instead as there's no other way of doing it. – Archimedes Trajano May 26 '21 at 03:50
0

Sure you can set up a template with resources, and use this template in a YAML pipeline. You can reference "Extend from a template with resources".

However, please note that if you have defined resources and steps in the template, you can't use it under the steps key in the YAML pipeline. You should use the extends key to extend the resources from the template, just like as the example shows in the document.

You may need to defined all the required steps in the template, or use the steps from other step template into the template.

Bright Ran-MSFT
  • 5,190
  • 1
  • 5
  • 12