Giter Site home page Giter Site logo

ravibhardwaj05 / azure-pipelines-monorepo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from julie-ng/azure-pipelines-monorepo

0.0 0.0 0.0 250 KB

Example of a multi-pipeline monorepo with Azure Pipelines

Home Page: https://julie.io/writing/monorepo-pipelines-in-azure-devops/

License: MIT License

JavaScript 100.00%

azure-pipelines-monorepo's Introduction

azure-pipelines-monorepo

Build Status

Use Case

This is not a recommendation to use a monorepo, just an example of how to implement it. Although uncommon, there are valid reasons to have a monorepo, especially for projects just migrating to the cloud.

In this scenario, we want to have multiple independent Azure DevOps pipelines in a single git repository.

Goal: multiple piplines in a single repo

Monorepo Structure

This project has 3 different YAML pipelines, one in the project root and two in subfolders as shown:

.
├── README.md
├── azure-pipelines.yml
├── service-a
|── azure-pipelines-a.yml
│   └── …
└── service-b
    |── azure-pipelines-b.yml
    └── …

Steps Required in Azure DevOps UI

In short, the trick is that you name your pipeline as code YAML file whatever you want - which was not true when Azure DevOps was first released. Given that, we create three different pipelines.

Fork the Repository (optional)

This is a public repository so you should be able to add this repository into your Azure DevOps account. Note: you may need to create a service connection to GitHub even though this is a public repository.

If you have issues, fork the repo.

Add the Pipeline

  1. Go to a project
  2. click "New Pipeline" blue button
  3. Select the repository
  4. Under "Configure your Pipeline", select "Existing Azure Pipelines YAML file". Run these steps 1-4 three times, each time selecting a different YAML file:
  • azure-pipelines.yml
  • service-a/azure-pipelines-a.yml
  • service-b/azure-pipelines-b.yml

Select a different YAML file path in the Azure DevOps UI

Rename your pipelines

The default names Azure DevOps are not great:

  • julie-ng.azure-devops-monorepo
  • julie-ng.azure-devops-monorepo (1)
  • julie-ng.azure-devops-monorepo (2)

I've renamed mine to:

  • azure-devops-monorepo (root)
  • azure-devops-monorepo (Service A)
  • azure-devops-monorepo (Service B)

You can rename the pipeline by clicking on the "3 dots" more options button and selecting "Rename/move". This button can be found at multiple places.

Rename your Pipeline in the Azure DevOps UI

Then you will have the setup in the first screenshot above.

How It Works

Root Pipeline

The pipeline in the root folder is defined to ignore changes in the subfolders:

trigger:
  paths:
    exclude: # Exclude!
      - 'service-a/*'
      - 'service-b/*'

Sub-project Pipelines

Each subfolder has a pipeline that is (CI) triggered by changes in its own directories.

trigger:
  paths:
    include: # Include!
      - 'service-a/*' # or 'service-b/*'

Note: the paths are always defined relative to the project root, not the location of the file.

Caveats!

There's a reason why monorepos are not common. If you choose this setup…

  • Be Aware of Other Triggers, not just CI ones
  • Are we Building A or B or both?
  • Keep your Working Directory in Mind, e.g. running npm install doesn't work from root. So you may need to set workingDirectory in each step.

For details, see my blog article Creating Monorepo Pipelines in Azure DevOps →

azure-pipelines-monorepo's People

Contributors

julie-ng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.