Using Lerna.js and Azure Devops Pipeline

大兔子大兔子 提交于 2021-01-29 21:37:00

问题


I'm studying about azuredevops pipelines to a new project. I'm totally new about devops.

In this project, I want to use lerna.js to manage my monorepo and my packages.

Considering that I have those three projects inside my monorepo:

  • Package 1 (1.0.1)
  • Package 2 (1.0.0)
  • Package 3 (1.0.3)

And I want to create a new TAG, which will increase the Package 3 to (1.0.4). How can I trigger an Azure Pipeline just to Package 3? There is any guide?

I watched one talk about monorepos with lerna.js and I'm trying to figure out if Azure Pipelines has one feature similar to what Sail CI does. In the exemple we have this approch:

tasks:
  build-package-1:
    image: sailci/demo
    when:
      paths:
        - "packages/package-1/**/*"

The company I'm working at is using Azure DevOps, would be awesome know if I can have that feature there.


回答1:


The closest thing similar to that one is like @Simon Ness wrote multiple pipelines with path filters. Additionally if your packages have similar strucutre and require the same steps to creeate/test/publish package you should consider templates.

The conspet toi handle packages like you described can be similar to below steps.

template.yaml

parameters:
- name: workingDir 
  type: string
  default: package-1

steps:
- script: npm install
  workingDiretory: ${{ parameters.workingDir }}
- script: yarn install
  workingDiretory: ${{ parameters.workingDir }}
- script: npm run compile
  workingDiretory: ${{ parameters.workingDir }}

then pipeline for Package-1 may look like this:


trigger:
  branches:
    include:
    - master
    - releases/*
  paths:
    include:
    - Package-1/*


steps:
- template: templates/template.yaml
  parameters:
    workingDir: Package-1

and for Package-2:


trigger:
  branches:
    include:
    - master
    - releases/*
  paths:
    include:
    - Package-2/*

steps:
- template: templates/template.yaml
  parameters:
    workingDir: Package-2

EDIT

For tag part all you need to do is change trigger section:

trigger:
  branches:
    include:
    - master
    - refs/tags/*

and when you create a tag and push it:

git tag release-05
git push origin --tags

your pipeline wil start:

However, trigger works like or condition, so for any change on master or new tag piepline will start. So if you tag another branch (not master) pipeline will start.

This is why you may need to check if your source branch is the one from trigger section:


trigger:
  branches:
    include:
    - master
    - refs/tags/*

stages:
- stage: A
  condition: eq(variables['Build.SourceBranch'], 'master')
  jobs:
  - job: JA
    steps:
    - script: |
        echo "This is job Foo."

Above pipeline will run for:

  • change in master branch
  • any tag pushed to server, but it runs stage A only if you push tag to master branch



回答2:


If you're happy to define a separate pipeline for each package take a look at paths in CI triggers.

Tags can be used as a trigger by including the branch - refs/tags/* in the triggers section.



来源:https://stackoverflow.com/questions/61783014/using-lerna-js-and-azure-devops-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!