SLN
SLN

Reputation: 5092

How to organize azure-pipeline.yaml files

I've read the official documents to put the yaml file in the root of a project. I'm thinking to create a some sort of pipeline repo that contains several yaml files in charge of different pipeline workflow for different project. But Azure pipeline only recognise the azure-pipeline.yaml file name.

Issue: It is obviously not possible to create several yaml files with the same azure-pipeline.yaml name under the same folder. What's the best practice to organise the azure pipeline yaml files? Shall it be just put in the root of the project?

Upvotes: 6

Views: 10108

Answers (2)

LoLance
LoLance

Reputation: 28196

It is obviously not possible to create several yaml files with the same azure-pipeline.yaml name under the same folder.

Yes, it's not possible to create several yaml pipelines with same name under same folder. Cause the yaml pipeline is under version control and Azure Devops git doesn't support two files with same name in same folder...

What we can do is to create several pipelines with different names in same folder, like azure-pipeline.yaml,azure-pipelines-1.yml,azure-pipelines-2.yml and so on.

Not sure if you know this option when editing yaml pipeline:

enter image description here

We can easily change the yaml file's name in source control, and we just need to modify the path here:

enter image description here

What's the best practice to organise the azure pipeline yaml files? Shall it be just put in the root of the project?

Assuming you own one Team Project with two repos A and B:

If A and B both represent the module of one final product, then you should have corresponding pipelines for A and B. It means in most scenarios, you should have at least one pipeline in RepoA and one in RepoB. They all need corresponding azure-pipeline.yaml file.

Now if azure-pipeline.yaml in RepoA and azure-pipeline.yaml in RepoB have many same variables/tasks/jobs, we can consider moving the duplicate contents into templates. We can create a RepoC in same project to store the templates, and in this templates repo, we don't need to create yaml pipeline here.

About how to reference templates in RepoC in RepoA's pipeline, see this document. If the source is in github, you can check Krzysztof's link. And if the RepoC is in Azure Devops Repos and same project with your RepoA and RepoB, you can should this format:

resources:
  repositories:
  - repository: templates
    type: git
    name: RepoC
    ref: refs/heads/master

To sum up, functional repos (those with source code) should have corresponding yaml pipeline in it. And if you want to monitor the changes in one repo (without source code) for some purpose, you can also have one yaml pipeline in that. For templates repo, yaml pipelines are not necessary.

Also, apart from yaml pipelines you may sometimes use Classic Build/Release pipelines which are not under Version Control. See this.

Upvotes: 5

Alexis Murray
Alexis Murray

Reputation: 698

It sounds like templates might be what you're looking for. This assumes you have a single project/repo and a large pipeline that you'd like to split up so it's easier to read or reason about individual parts.

Taking an example from the linked documentation page, you can define a template yaml file like this (ex: include-npm-steps.yml):

steps:
- script: npm install
- script: yarn install
- script: npm run compile

And then include it as a "module" in the main azure-pipelines.yml file like this:

jobs:
- job: Linux
  pool:
    vmImage: 'ubuntu-latest'
  steps:
  - template: templates/include-npm-steps.yml  # Template reference
- job: Windows
  pool:
    vmImage: 'windows-latest'
  steps:
  - template: templates/include-npm-steps.yml  # Template reference

Upvotes: 6

Related Questions