• Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • nodejs-plugin
    • Linux, Jenkins 1.612, NodeJS-plugin 0.2.1

      I'd like to set properties in the .npmrc after NPM is installed. Specifically, I'd like to set the 'registry' option to point to a local registry, as mentioned here: https://books.sonatype.com/nexus-book/reference/npm-configuring.html
      I couldn't find a way to specify this now, so could this be added?

          [JENKINS-30615] Allow specifying global NMP settings

          Nikolas Falco added a comment -

          For portable and secure configuration the config-file-plugin could be useful

          Nikolas Falco added a comment - For portable and secure configuration the config-file-plugin could be useful

          Nikolas Falco added a comment -

          Just now a workaround you could use config-file-plugin.
          Configure a "Custom file", put there your npm settings and then in the job configuration enable Provide Configuration files settings and as target put ${WORKSPACE}/.npmrc
          That location is one of 4/5 default location where npm lookup for the configuration file.
          That file will be deleted after jenkins job ends or is stopped.

          Nikolas Falco added a comment - Just now a workaround you could use config-file-plugin. Configure a " Custom file ", put there your npm settings and then in the job configuration enable Provide Configuration files settings and as target put ${WORKSPACE}/.npmrc That location is one of 4/5 default location where npm lookup for the configuration file. That file will be deleted after jenkins job ends or is stopped.

          Nikolas Falco added a comment -

          This feature is totally supported by implementation of JENKINS-40364

          Nikolas Falco added a comment - This feature is totally supported by implementation of JENKINS-40364

          rross added a comment - - edited

          I disagree that this has been "totally supported by implementation of JENKINS-40364".  As I understand (and experience) it, this request is for a GLOBAL specification per NPM configuration.  While JENKSINS-40364 does give you a way to muddle through this, it is particularly painful when you're dealing with multi-project declarative pipeline scripts (Jenkinsfile).  In that situation, unless I'm mistaken, you have to wrap and redeclare the configuration you want to use over and over for every stage in the pipeline script.  This is very clunky and not in the spirit of what a "Global" configuration would achieve.  With a global configuration, you would set it up once, associated with the node version configuration, and then simply use it via something in your Jenkinsfile declared one time like:
           

            tools {
               nodejs 'NodeJS-LTS'
            }

           

          Where "NODEJS-LTS" was the name of a configuration node instance.  If this ticket were implemented, that one declaration would also carry in the associated .npmrc configuration and apply it across the entire script instead of having to do this:

            stages {
              stage('Setup') {
                 nodejs(nodeJSInstallationName: 'NodeJS-LTS', configId: 'internal-artifact-repo') {
                   // Do some node stuff.
                 }
               }
              stage('Build') {
                 nodejs(nodeJSInstallationName: 'NodeJS-LTS', configId: 'internal-artifact-repo') {
                   // Do some node stuff.
                 }
              }
              stage('Publish') {
                 nodejs(nodeJSInstallationName: 'NodeJS-LTS', configId: 'internal-artifact-repo') {
                   // Do some node stuff.
                 }
              }
             }
          

           
          They're quite different when you try to actually use them.  This is especially true if you're managing a large group of developers across multiple projects all working with a single internal NPM repository.  If there's a way to do this at a GLOBAL level right now, someone please let me know how.

           

          rross added a comment - - edited I disagree that this has been "totally supported by implementation of  JENKINS-40364 " .  As I understand (and experience) it, this request is for a GLOBAL specification per NPM configuration.  While JENKSINS-40364 does give you a way to muddle through this, it is particularly painful when you're dealing with multi-project declarative pipeline scripts (Jenkinsfile).  In that situation, unless I'm mistaken, you have to wrap and redeclare the configuration you want to use over and over for every stage in the pipeline script.  This is very clunky and not in the spirit of what a "Global" configuration would achieve.  With a global configuration, you would set it up once, associated with the node version configuration, and then simply use it via something in your Jenkinsfile declared one time like:     tools {      nodejs  'NodeJS-LTS' }   Where "NODEJS-LTS" was the name of a configuration node instance.  If this ticket were implemented, that one declaration would also carry in the associated .npmrc configuration and apply it across the entire script instead of having to do this:   stages {     stage( 'Setup' ) {        nodejs(nodeJSInstallationName: 'NodeJS-LTS' , configId:  'internal-artifact-repo' ) { // Do some node stuff.       }     }     stage( 'Build' ) {        nodejs(nodeJSInstallationName: 'NodeJS-LTS' , configId:  'internal-artifact-repo' ) { // Do some node stuff.       }     }     stage( 'Publish' ) {        nodejs(nodeJSInstallationName: 'NodeJS-LTS' , configId:  'internal-artifact-repo' ) { // Do some node stuff.       }     }   }   They're quite different when you try to actually use them.  This is especially true if you're managing a large group of developers across multiple projects all working with a single internal NPM repository.  If there's a way to do this at a GLOBAL level right now, someone please let me know how.  

          Nikolas Falco added a comment -

          NodeJS plugin base its configuration on configFileProvider. This mean you can set the .npmrc following these rules: https://docs.npmjs.com/cli/v6/using-npm/config#npmrc-files

          stages {
              configFileProvider([configFile(fileId: 'artifactory.npm', targetLocation: '${WORKSPACE}', variable: 'NPM_CONFIG_USERCONFIG')]) {
                // or NPM_CONFIG_GLOBALCONFIG
                stage('Setup') {
                  nodejs(nodeJSInstallationName: 'NodeJS-LTS') {
                    // Do some node stuff.
                  }
                }
                stage('Build') {
                  nodejs(nodeJSInstallationName: 'NodeJS-LTS') {
                    // Do some node stuff.
                  }
                }
                stage('Publish') {
                  nodejs(nodeJSInstallationName: 'NodeJS-LTS') {
                    // Do some node stuff.
                  }
                }
              }
          }
          
          

          Nikolas Falco added a comment - NodeJS plugin base its configuration on configFileProvider. This mean you can set the .npmrc following these rules: https://docs.npmjs.com/cli/v6/using-npm/config#npmrc-files stages { configFileProvider([configFile(fileId: 'artifactory.npm' , targetLocation: '${WORKSPACE}' , variable: 'NPM_CONFIG_USERCONFIG' )]) { // or NPM_CONFIG_GLOBALCONFIG stage( 'Setup' ) { nodejs(nodeJSInstallationName: 'NodeJS-LTS' ) { // Do some node stuff. } } stage( 'Build' ) { nodejs(nodeJSInstallationName: 'NodeJS-LTS' ) { // Do some node stuff. } } stage( 'Publish' ) { nodejs(nodeJSInstallationName: 'NodeJS-LTS' ) { // Do some node stuff. } } } }

          rross added a comment -

          Thanks, this confirms what I realized about 10 minutes after I sent my previous message.  I can generate an `.npmrc` file in the build workspace and that should be used by any calls to npm from the build.  Much cleaner!

          rross added a comment - Thanks, this confirms what I realized about 10 minutes after I sent my previous message.  I can generate an `.npmrc` file in the build workspace and that should be used by any calls to npm from the build.  Much cleaner!

            Unassigned Unassigned
            jvetechno Jeroen van der Vegt
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: