title: Update package.json version using Azure Dev Ops Build pipeline
body: <p>I am trying to dynamically update a package.json as part of a CI build for publishing to an npm repository.</p>
  <p>I am following a simple scheme of yyyymm.dd.rev to create the version number.</p>
  <p>I have followed <a href="https://stackoverflow.com/questions/65266297/npm-version-in-azure-devops-pipeline/65282736">npm version in Azure Dev Ops pipeline</a>.</p>
  <p>My powershell script to update variables:</p>
  <pre><code>variables:
    major: 1
    minor: 0
    patch: 0
    rev: 0
    packageVersion: '$(major)$(minor).$(patch).$(rev)'
  
  steps:
  
    - task: PowerShell@2
      displayName: Set SemVer values
      inputs:
        targetType: 'inline'
        script: |
          $year = Get-Date -Format &quot;yyyy&quot;
          $month = Get-Date -Format &quot;MM&quot;
          $day = Get-Date -Format &quot;dd&quot;
          $rev = Get-Date -Format &quot;HHmm&quot;
          Write-Host &quot;##vso[task.setvariable variable=major]$year&quot;
          Write-Host &quot;##vso[task.setvariable variable=minor]$month&quot;
          Write-Host &quot;##vso[task.setvariable variable=patch]$day&quot;   
          Write-Host &quot;##vso[task.setvariable variable=rev]$rev&quot;  
  </code></pre>
  <p>With the variable set - I am calling the npm version command to update the package.json</p>
  <pre><code>  - task: Npm@1
      displayName: Update Version of my package
      inputs:
        command: 'custom'
        workingDir: 'libs/my-package'
        customCommand: 'version $(packageVersion) --no-git-tag-version --loglevel verbose'
  </code></pre>
  <p>I keep getting an npm failure.  This runs fine if I execute it locally - just on the build server do I see failure:</p>
  <pre><code>/usr/local/bin/npm --version
  6.14.15
  /usr/local/bin/npm config list
  ; cli configs
  metrics-registry = &quot;https://registry.npmjs.org/&quot;
  scope = &quot;&quot;
  user-agent = &quot;npm/6.14.15 node/v14.18.1 linux x64&quot;
  
  ; environment configs
  userconfig = &quot;/home/vsts/work/1/npm/17197.npmrc&quot;
  
  ; node bin location = /usr/local/bin/node
  ; cwd = /home/vsts/work/1/s/libs/my-library
  ; HOME = /home/vsts
  ; &quot;npm config ls -l&quot; to show all defaults.
  
  **/usr/local/bin/npm version 202111.04.1901 --no-git-tag-version --loglevel verbose**
  npm info it worked if it ends with ok
  npm verb cli [
  npm verb cli   '/usr/local/bin/node',
  npm verb cli   '/usr/local/bin/npm',
  npm verb cli   'version',
  npm verb cli   '202111.04.1901',
  npm verb cli   '--no-git-tag-version',
  npm verb cli   '--loglevel',
  npm verb cli   'verbose'
  npm verb cli ]
  npm info using npm@6.14.15
  npm info using node@v14.18.1
  npm ERR! npm version [&lt;newversion&gt; | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=&lt;prerelease-id&gt;] | from-git]
  npm ERR! (run in package dir)
  npm ERR! 'npm -v' or 'npm --version' to print npm version (6.14.15)
  npm ERR! 'npm view &lt;pkg&gt; version' to view a package's published version
  npm ERR! 'npm ls' to inspect current package/dependency versions
  npm verb exit [ 1, true ]
  npm timing npm Completed in 117ms
  npm verb code 1
  ##[warning]Couldn't find a debug log in the cache or working directory
  ##[error]Error: Npm failed with return code: 1
  Finishing: Update Version of my package
  </code></pre>