1

Hello I try to execute nodejs job in jenkins:

Jenkins integration with Grunt

But I can't connect to registry.npmjs.org/ throw Jenkins. I set the Proxy in Jenkins in Plugins->Advanced but I get stil this error:

Started by user anonymous
Building in workspace /var/lib/jenkins/jobs/TempDemo/workspace
$ /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/recent_node_0.11.11_/bin/npm install -g grunt-cli@~0.1.0
npm http GET https://registry.npmjs.org/grunt-cli
npm http GET https://registry.npmjs.org/grunt-cli
npm http GET https://registry.npmjs.org/grunt-cli
npm ERR! Error: connect ECONNREFUSED
npm ERR!     at exports._errnoException (util.js:682:11)
npm ERR!     at Object.afterConnect [as oncomplete] (net.js:947:19)
npm ERR!  { [Error: connect ECONNREFUSED]
npm ERR!   stack: 'Error: connect ECONNREFUSED\n    at exports._errnoException (util.js:682:11)\n    at Object.afterConnect [as oncomplete] (net.js:947:19)',
npm ERR!   code: 'ECONNREFUSED',
npm ERR!   errno: 'ECONNREFUSED',
npm ERR!   syscall: 'connect' }
npm ERR! 
npm ERR! If you are behind a proxy, please make sure that the
npm ERR! 'proxy' config is set properly.  See: 'npm help config'

What should I do now?

Community
  • 1
  • 1
Ivan Demin
  • 101
  • 2
  • 9

2 Answers2

1

I only have a stopgap solution to this as I couldn't find any information on configuring the plugin to work with a proxy. I created a wrapper around the npm executable which sets the proxy details before calling the underlying npm script. The steps:

  1. Setup the NodeJS Installation, start a job which uses it and get the failure (as above). This should leave a Node installation folder in /tools. I see for you this is "/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/recent_node_0.11.11_".

  2. Navigate to the /bin folder at this location.

  3. Rename the npm executable link: "mv npm npm-actual"

  4. Create a new npm file: touch npm

  5. Set the contents as follows:

    \#!/bin/sh
    
    /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/recent_node_0.11.11_/bin/npm-actual config set proxy "<proxy url with optional credentials>"
    
    /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/recent_node_0.11.11_/bin/npm-actual config set https-proxy "<proxy url with optional credentials>"
    
    /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/recent_node_0.11.11_/bin/npm-actual "$@"
    
  6. Be sure that this new npm script is owned by the Jenkins user and that it is marked executable.

Re-run the Jenkins job, it should this time make use of the proxy settings above and be able to download what it needs. These settings mimic those found in ~/.npmrc and more info can be found here:

http://jjasonclark.com/how-to-setup-node-behind-web-proxy

Hope that helps. If anyone has a better, more correct solution I'd love to hear it as well.

John G
  • 58
  • 1
  • 6
1

You can set NPM to use a proxy, you may need to sudo

npm config set proxy http://yourproxy.com:80
am80l
  • 1,511
  • 12
  • 11