如何在 Mono-Repo 中指定为 azure-pipelines.yml 构建包的路径?

How to specify path to build a package for azure-pipelines.yml in a Mono-Repo?

我有一个文件夹结构如下的 monorepo:

如何修改 azure-pipelines.yml 来构建 packageA

我尝试通过指定 packageA 的路径来更改 azure-pipelines.yml。但是,我是 ci/cd 的新手,所以我不确定如何解决我的问题。目前我有这个作为我的 azure-pipelines.yml 文件:

# Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
  branches:
    include:
    - master

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'

- script: |
    npm install
    npm run unit_tests
  displayName: 'npm install and build'

.yml 文件位于 monorepo 的根文件夹中。管道构建将失败,因为它无法在 packageA

中找到 package.json 到 运行 的 npm 命令

这里的解决方法是在脚本任务下使用一个bash脚本。例如,解决方法如下所示:

- script: | 
    cd server && npm run install
    npm run install mocha-junit-reporter
    npm run unit_tests 
  displayName: 'npm install and build'

scriptCommand Line Task

的快捷方式

您可以指定一个工作目录,您的脚本将在其中 运行

- script: # script path or inline
  workingDirectory: #
  displayName: #
  failOnStderr: #
  env: { string: string } # mapping of environment variables to add

根据我的经验,在不同的目录中为 运行 指定多个脚本会失败,我的解决方法是使用两个脚本任务,例如:

- script: npm install
  workingDirectory: client
  displayName: 'npm install'

- script: npm run build
  workingDirectory: client
  displayName: 'npm run build'

这是我自己的管道中的代码