Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-71447

Impossible to change env for NodeJSInstallation's global packages installation

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Minor Minor
    • nodejs-plugin
    • None

      I am trying to install Node.js 16 on several Nodes with the help of Jenkinsfile. It goes fine everywhere except old Windows 7, because there I must set the NODE_SKIP_PLATFORM_CHECK environment variable to suppress an error.

      I tried to put the whole nodejs() tool invoation inside withEnv block like this, but it has no effect:

      withEnv(['NODE_SKIP_PLATFORM_CHECK=1']) {
              nodejs(configId: 'NPM_Standard', nodeJSInstallationName: 'NodeJS16') {
              // do smth
              }
      }

      Output:
      cmd /c d:\build-windows-01\tools\jenkins.plugins.nodejs.tools.NodeJSInstallation\NodeJS16\npm.cmd install -g node-addon-api nan express typescript commander javascript-obfuscator mocha
      Node.js is only supported on Windows 8.1, Windows Server 2012 R2, or higher. Setting the NODE_SKIP_PLATFORM_CHECK environment variable to 1 skips this

       

      It does work, because the installation of global packages is run by the function `refreshGlobalPackages` which runs "npm install -g" inside a clean env: https://github.com/jenkinsci/nodejs-plugin/blob/master/src/main/java/jenkins/plugins/nodejs/tools/NodeJSInstaller.java#L227.

      It does not even respect the environment variables which are set in Jenkins per node.
      I managed to bypass it only by setting this variable in Windows configuration on the node itself which is very inconvenient and not a Jenkins way of programming.

      My expectation is withEnv must affect anything which is inside it. Probably it is worth to fix it more generally, not only for NodeJSInstallation if other global tools also neglect withEnv and Node env like NodeJSInstallation.

       

            nfalco Nikolas Falco
            alexander_samoylov Alexander Samoylov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: