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

NodeJS Installation Caching replaces Symlinks with original files which breaks installations

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • nodejs-plugin
    • None
    • Jenkins-Version 2.329
      NodeJS-Plugin in Version 1.5.0
      on Amazon Linux 2
      NodeJS version 14.17.0
    • 1.5.1

      Problem

      The NodeJS Installation Caching (introduced in NodeJS-Plugin version 1.5.0) uses zip-files to cache the installations. Zipping replaces all symlinks with the original files (see here, describes also the here occured problem). This raises an error, because the npm-file in "bin" is added to the $PATH is normally a symlink:
      npm -> ../lib/node_modules/npm/bin/npm-cli.js

      But after the installation from the cache the npm-file in the "bin"-folder is the binary on which the symlink orginally pointed. Because of that npm is not finding needed files with relative path:

      Installing NodeJS from /var/lib/jenkins/caches/nodejs/LINUX/amd64/14.17.0.zip to /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/nodejs on EC2 (aws-frankfurt) - Jenkins-Agent (i-053ae1c2b0b9b9ccb)
      $ /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/nodejs/bin/npm install -g eslint gulp jasmine tslint typescript @angular/cli grunt sonarqube-scanner claudia@5.14.0 nyc stryker-cli npm-audit-ci  audit-ci
      internal/modules/cjs/loader.js:888
        throw err;
        ^
      
      Error: Cannot find module '../lib/utils/unsupported.js'
      Require stack:
      - /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/nodejs/bin/npm
          at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
          at Function.Module._load (internal/modules/cjs/loader.js:730:27)
          at Module.require (internal/modules/cjs/loader.js:957:19)
          at require (internal/modules/cjs/helpers.js:88:18)
          at /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/nodejs/bin/npm:19:21
          at Object.<anonymous> (/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/nodejs/bin/npm:155:3)
          at Module._compile (internal/modules/cjs/loader.js:1068:30)
          at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
          at Module.load (internal/modules/cjs/loader.js:933:32)
          at Function.Module._load (internal/modules/cjs/loader.js:774:14) {
        code: 'MODULE_NOT_FOUND',
        requireStack: [
          '/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/nodejs/bin/npm'
        ]
      }
      

      Steps to reproduce

      1. Start a new agent and run a job on it, which installs NodeJS on the node. The plugin performs caching of the installation on the master. Here npm is working, beacuse it is installed from the internet from a tar-archive.
      2. Start a new node and also run a job on it, that installs NodeJS. The installation is performed from the cache from a zip-file and the first call of npm will raise the above error.

      Possible solution

      Here it is suggested to use tar-compressing instead of zip-compression to perserve symlinks.

      Workaround

      Add the folloing option to the Jenkins-Config-File in /etc/sysconfig/jenkins to disable the caching:

      JENKINS_JAVA_OPTIONS="[...] -Djenkins.plugins.nodejs.tools.NodeJSInstaller.cache.disable=true"
      

            nfalco Nikolas Falco
            krotanhill Christoph Lusts
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: