title: Writing a Jenkins Pipeline Shared Library to publish to Nexus NPM repository
body: <p>I used to publish my NPM projects to Nexus using a DSL pipeline containing a publish stage with this kind of step : </p>
  
  <pre><code>stage ('Publish') {
    nodejs(nodeJSInstallationName: 'Node LTS', configId: '123456ab-1234-abcd-1234-f123d45e6789') {
      sh 'npm publish'
    }
  }
  </code></pre>
  
  <p>I have a NodeJS installation named "Node LTS" on my Jenkins and a npmrc config file with this configId.</p>
  
  <p>Now I want to export this stage into a groovy SharedLib.
  According to <a href="https://jenkins.io/doc/book/pipeline/syntax/" rel="noreferrer">Declarative Pipeline documentation</a> and <a href="https://issues.jenkins-ci.org/browse/JENKINS-40624" rel="noreferrer">this nodejs-plugin issue</a>, I could write this : </p>
  
  <pre><code>    stage('Publish') {
          tools {
              nodejs 'Node LTS'
          }
          steps {
              sh 'npm publish'
          }
      }
  </code></pre>
  
  <p>But this does not set authentification configuration that is currently in my npmrc configuration file : </p>
  
  <pre><code>registry=http://my-nexus/repository/npm-private/
  _auth="some=base=64=credential=="
  always-auth=true
  </code></pre>
  
  <p>Any idea to retreive this configuration with declarative syntax and prevent this error message ?</p>
  
  <pre><code>npm ERR! code ENEEDAUTH
  npm ERR! need auth auth required for publishing
  npm ERR! need auth You need to authorize this machine using `npm adduser`
  </code></pre>