For our pipeline we have two windows self-hosted agents installed on the same computer. Our main front-end pipeline .yml is listed below. This works fine except for some reason the npm install doesn't get nx, or jest. To fix this we can just run npm install -g nx and npm install -g jest once in the pipeline for each agent. After the first run it is fine and we can remove the extra installs to speed up execution. However, it won't update when new versions of nx or jest are released and this definitely isn't best practices.
I am guessing the problem is that these need to be install globally to work so the regular npm install can't achieve that. I included a slightly modified version of our package.json which shows that nx (@nrwl) and jest are included in the package. Does anyone know a better way to install the nx and jest without reinstalling them each pipeline build and without removing install statements after the first run with a new agent? Thank you in advance for any suggestions, please let me know if I can provide any additional information.
trigger:
- none
pool: 'myPool'
variables:
npm_config_cache: $(Pipeline.Workspace)/.npm
steps:
- checkout: self
clean: true
- task: NodeTool@0
inputs:
versionSpec: '12.x'
displayName: 'Install Node.js'
# Install stuff
- task: Npm@1
timeoutInMinutes: 10
inputs:
command: 'install'
workingDir: '$(System.DefaultWorkingDirectory)/ID_CLIENT'
displayName: 'npm install'
# Test stuff
- script: nx affected:lint --base=origin/master --skip-nx-cache=true --parallel
timeoutInMinutes: 10
workingDirectory: '$(System.DefaultWorkingDirectory)/ID_CLIENT'
displayName: 'run lint'
- script: 'jest --ci --reporters=default --reporters=jest-junit'
timeoutInMinutes: 10
workingDirectory: '$(System.DefaultWorkingDirectory)/ID_CLIENT'
displayName: 'Run Tests'
continueOnError: 'true'
# Build stuff
- script: nx affected:build --base=origin/master --skip-nx-cache=true --parallel
timeoutInMinutes: 10
workingDirectory: '$(System.DefaultWorkingDirectory)/ID_CLIENT'
displayName: 'prod build'
# Publish test results to Azure Pipelines
- task: PublishTestResults@2
timeoutInMinutes: 10
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/junit.xml'
searchFolder: '$(System.DefaultWorkingDirectory)'
failTaskOnFailedTests: true
{
"name": "project",
"version": "1.0.0",
"scripts": {
"install:hard": "rimraf \"node_modules/!(rimraf)\" && npm cache clear --force && npm install",
"install:globals": "npm install -g jest-cli @nrwl/cli",
"postinstall": "ngcc"
},
"private": true,
"dependencies": {
"@angular/animations": "~9.1.4",
"@angular/common": "~9.1.4",
"@angular/compiler": "~9.1.4",
"@angular/core": "~9.1.4",
"@angular/forms": "~9.1.4",
"@angular/localize": "^9.1.6",
"@angular/platform-browser": "~9.1.4",
"@angular/platform-browser-dynamic": "~9.1.4",
"@angular/router": "~9.1.4",
"@ng-bootstrap/ng-bootstrap": "^6.1.0",
"@ngneat/until-destroy": "^7.3.0",
"angular-datatables": "^9.0.1",
"angulartics2": "^9.1.0",
"bootstrap": "^4.4.1",
"core-js": "^3.1.4",
"jest-junit": "^12.0.0",
},
"devDependencies": {
"@nrwl/angular": "^10.3.0",
"@nrwl/jest": "^10.3.0",
"@nrwl/workspace": "^10.3.0",
"jest": "^26.4.2",
"jest-canvas-mock": "^2.3.0",
"jest-cli": "^26.4.2",
"jest-preset-angular": "^8.3.1",
"jest-skipped-reporter": "0.0.5",
"ts-jest": "^26.4.1",
"typescript": "^3.8.3",
}
}
Edit: I tried adding "nx": "^10.3.0" and "@nrwl/cli": "^10.3.0" to the dev dependencies and then after installing I ran npm run nx test. It gave me npm ERR! missing script: nx. Did I just not add it correctly?