Azure DevOps Pipeline Global Package Installs Best Practices

0 votes

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?

Apr 4, 2022 in Azure by Edureka
• 13,620 points
1,810 views

1 answer to this question.

0 votes
So, if you want to maintain your global tools up to date without having to run those commands every time your pipeline runs, establish a new scheduled pipeline to run it once per day and update your global tools.
answered Apr 4, 2022 by Edureka
• 12,690 points

Related Questions In Azure

0 votes
1 answer
0 votes
0 answers

C# NuGet package error in Azure DevOps with image

I'm creating a NuGet package to distribute ...READ MORE

Apr 12, 2022 in Azure by Edureka
• 13,620 points
377 views
0 votes
1 answer
0 votes
1 answer

What is the Difference between VSO, VSTS and Azure Devops

Azure DevOps was previously known as VSO ...READ MORE

answered Mar 8, 2022 in Azure by Edureka
• 13,620 points

edited Jun 27, 2023 by Khan Sarfaraz 1,340 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,691 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,233 views
0 votes
1 answer

sudo: npm: command not found

To answer your question, for me, the ...READ MORE

answered Feb 17, 2022 in Others by Aditya
• 7,680 points
4,608 views
0 votes
1 answer

Add run id when registering ml.azure model via python (pipeline)

Create the following resources in order to ...READ MORE

answered Mar 1, 2022 in Azure by Edureka
• 12,690 points
749 views
0 votes
1 answer

Add image to Azure Devops Dashboard

Markdown is a web writer's text-to-HTML conversion ...READ MORE

answered Mar 26, 2022 in Azure by Edureka
• 12,690 points
504 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP