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

Kal*_*ari 5 continuous-integration pipeline azure-devops azure-pipelines monorepo

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

  • ->包A
  • ->包B
  • ->包C

如何更改 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://learn.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'
Run Code Online (Sandbox Code Playgroud)

.yml 文件位于 monorepo 的根文件夹中。管道构建将失败,因为它找不到 package.json 来运行 packageA 中的 npm 命令

小智 7

script是命令行任务的快捷方式

您可以指定运行脚本的工作目录

- script: # script path or inline
  workingDirectory: #
  displayName: #
  failOnStderr: #
  env: { string: string } # mapping of environment variables to add
Run Code Online (Sandbox Code Playgroud)

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

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

- script: npm run build
  workingDirectory: client
  displayName: 'npm run build'
Run Code Online (Sandbox Code Playgroud)

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


Kal*_*ari 2

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

- script: | 
    cd server && npm run install
    npm run install mocha-junit-reporter
    npm run unit_tests 
  displayName: 'npm install and build'
Run Code Online (Sandbox Code Playgroud)