Reputation: 113
I have a monorepo with a folder structure like this:
How can I alter the azure-pipelines.yml to build packageA
I have tried altering the azure-pipelines.yml by specifying the path to packageA. However, I am a newbie to ci/cd so I am not sure how to solve my problem. Currently I have this as my azure-pipelines.yml file:
# 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'
The .yml file is in the root folder of the monorepo. The pipeline build will fail because it cannot find the package.json to run the npm commands in packageA
Upvotes: 5
Views: 7618
Reputation: 113
The solution here is to use a bash script under the script task. For example the workaround looks something like this:
- script: |
cd server && npm run install
npm run install mocha-junit-reporter
npm run unit_tests
displayName: 'npm install and build'
Upvotes: 2
Reputation: 259
script
is a shortcut to the Command Line Task
You are able to specify a working directory in which your scripts will run
- script: # script path or inline
workingDirectory: #
displayName: #
failOnStderr: #
env: { string: string } # mapping of environment variables to add
In my experience specifying more than one script to run in a different directory fails, my fix is to use two script tasks such as:
- script: npm install
workingDirectory: client
displayName: 'npm install'
- script: npm run build
workingDirectory: client
displayName: 'npm run build'
This is the code from my own pipelines
Upvotes: 7