title: Azure DevOps Pipeline Global Package Installs Best Practices
body: <p>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 <code>npm install</code> doesn't get nx, or jest. To fix this we can just run <code>npm install -g nx</code> and <code>npm install -g jest</code> 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.</p>
  <p>I am guessing the problem is that these need to be install globally to work so the regular <code>npm install</code> can't achieve that. I included a slightly modified version of our <code>package.json</code> 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.</p>
  <pre><code>
  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
  </code></pre>
  <pre><code>{
    &quot;name&quot;: &quot;project&quot;,
    &quot;version&quot;: &quot;1.0.0&quot;,
    &quot;scripts&quot;: {
      &quot;install:hard&quot;: &quot;rimraf \&quot;node_modules/!(rimraf)\&quot; &amp;&amp; npm cache clear --force &amp;&amp; npm install&quot;,
      &quot;install:globals&quot;: &quot;npm install -g jest-cli @nrwl/cli&quot;,
      &quot;postinstall&quot;: &quot;ngcc&quot;
    },
    &quot;private&quot;: true,
    &quot;dependencies&quot;: {
      &quot;@angular/animations&quot;: &quot;~9.1.4&quot;,
      &quot;@angular/common&quot;: &quot;~9.1.4&quot;,
      &quot;@angular/compiler&quot;: &quot;~9.1.4&quot;,
      &quot;@angular/core&quot;: &quot;~9.1.4&quot;,
      &quot;@angular/forms&quot;: &quot;~9.1.4&quot;,
      &quot;@angular/localize&quot;: &quot;^9.1.6&quot;,
      &quot;@angular/platform-browser&quot;: &quot;~9.1.4&quot;,
      &quot;@angular/platform-browser-dynamic&quot;: &quot;~9.1.4&quot;,
      &quot;@angular/router&quot;: &quot;~9.1.4&quot;,
      &quot;@ng-bootstrap/ng-bootstrap&quot;: &quot;^6.1.0&quot;,
      &quot;@ngneat/until-destroy&quot;: &quot;^7.3.0&quot;,
      &quot;angular-datatables&quot;: &quot;^9.0.1&quot;,
      &quot;angulartics2&quot;: &quot;^9.1.0&quot;,
      &quot;bootstrap&quot;: &quot;^4.4.1&quot;,
      &quot;core-js&quot;: &quot;^3.1.4&quot;,
      &quot;jest-junit&quot;: &quot;^12.0.0&quot;,
    },
    &quot;devDependencies&quot;: {
      &quot;@nrwl/angular&quot;: &quot;^10.3.0&quot;,
      &quot;@nrwl/jest&quot;: &quot;^10.3.0&quot;,
      &quot;@nrwl/workspace&quot;: &quot;^10.3.0&quot;,
      &quot;jest&quot;: &quot;^26.4.2&quot;,
      &quot;jest-canvas-mock&quot;: &quot;^2.3.0&quot;,
      &quot;jest-cli&quot;: &quot;^26.4.2&quot;,
      &quot;jest-preset-angular&quot;: &quot;^8.3.1&quot;,
      &quot;jest-skipped-reporter&quot;: &quot;0.0.5&quot;,
      &quot;ts-jest&quot;: &quot;^26.4.1&quot;,
      &quot;typescript&quot;: &quot;^3.8.3&quot;,
    }
  }
  </code></pre>
  <p><strong>Edit:</strong> I tried adding <code>&quot;nx&quot;: &quot;^10.3.0&quot;</code> and <code>&quot;@nrwl/cli&quot;: &quot;^10.3.0&quot;</code> to the dev dependencies and then after installing I ran <code>npm run nx test</code>. It gave me <code>npm ERR! missing script: nx</code>. Did I just not add it correctly?</p>