Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Pipelines for mono-repo with multiple projects to build only updated one

I'm trying to build CI/CD for multiple java projects that are contained in one repo with Azure pipelines.

For this purpose was requirement to create one pipeline which will build every project with Maven@3 task. The problem is that when we add new project I want that only this one project was built and not every previous project. My file looks like :

    resources:
- repo: self
  clean: true
  lfs: true

trigger:
  branches:
    include:
      - feature/*

variables:
  - group: vars

stages:
- stage: Build
  pool:
    vmImage: 'image' 
  jobs:
  - job: Build
    strategy:
      maxParallel: 4
    steps:
    - task: replacetokens@3
      inputs:
        targetFiles: 'settings.xml'
    - task: Maven@3
      inputs:
        jdkVersionOption: 1.8
        mavenPomFile: 'project1/pom.xml'
        options: '-s $(Build.SourcesDirectory)\settings.xml'
        goals: 'clean package'
    - task: Maven@3
      inputs:
        jdkVersionOption: 1.8
        mavenPomFile: 'project2/pom.xml'
        options: '-s $(Build.SourcesDirectory)\settings.xml'
        goals: 'clean package'

For example project1 is alraedy in develop, so I don't want to do mvn package for it, but only for project2, which is this not merged and has feature branch.

For now this yml won't work because project1 and project2 are in the same repo and this two task will run, which I wan t to avoid.

Is there some way to say "onChange" ???

like image 506
Bohdan Myslyvchuk Avatar asked Mar 02 '20 14:03

Bohdan Myslyvchuk


People also ask

What are the two ways for Azure pipelines to be built?

Azure Pipelines combines continuous integration (CI) and continuous delivery (CD) to test and build your code and ship it to any target. Continuous Integration (CI) is the practice used by development teams of automating merging and testing code.

Can Azure DevOps project have multiple repos?

Specify multiple repositories Repositories can be specified as a repository resource, or inline with the checkout step. The following repository types are supported. Only Azure Repos Git ( git ) repositories in the same organization as the pipeline are supported for multi-repo checkout in Azure DevOps Server 2020.

Can builds & Deployments be scheduled in Azure pipelines?

Scheduled builds aren't supported in YAML syntax in this version of Azure DevOps Server. After you create your YAML build pipeline, you can use pipeline settings to specify a scheduled trigger. YAML isn't supported in TFS. Scheduled builds always run on schedule regardless of code changes on TFS 2018.1 and lower.


1 Answers

Unfortunately, this is not possible out of the box which is a shame, to be honest.

The easiest way to handle this would be to create two separate builds. One build for each project you want to build that is located in the same repo and use the path filter like this:

trigger:
  branches:
    include:
    - master
    - releases/*
  paths:
    include:
    - docs/*
    exclude:
    - docs/README.md

Use step templates and define a single build task or job that you can then use across multiple builds so it is easier to maintain if multiple projects have the same build steps.

Link to the documentation: https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema#step-templates

There are however guides on the internet where people did some Powershell scripting to achieve the mono repo single build solution.

One example would be this:

https://dev.to/nikolicbojan/azure-devops-yaml-build-for-mono-repository-with-multiple-projects-146g

like image 196
Repcak Avatar answered Oct 04 '22 05:10

Repcak