Jenkins npm: not found, despite node plugin

Viewed 333

I have a multibranch pipeline that uses many agents. The agents are all the same (supposedly) - they are all openstack instances created from the same snapshot. All of these instances have node and npm installed globally, which I confirmed by ssh'ing in to each one under various usernames and checking node -v and npm -v, and getting expected version numbers. I had been running into problems with Jenkins throwing npm: not found, so I followed this answer from "Jenkins unable to find npm", which was to use the node plugin. In my pipeline:

pipeline {
    agent {
        node {
            label 'agent-1'
        }
    }
    options {
        disableConcurrentBuilds()
    }
    tools {
        nodejs 'NodeJS 14.10.1'
    }
    stages {
        stage ('Parallel tests'){
            steps {
                script {
                    parallel parallelStages
                }
            }
        }
    }
}

Where parallelStages is a collection that contains a bunch of parallel stages, each one running on its own agent, and requiring use of npm. To avoid question bloat, I'll leave that code out, but you can see it in my other question here. Adding nodejs under tools helped solve this npm: not found problem the first time.

I just added a new stage to parallelStages, with a newly minted agent. I am again running into that old issue of npm: not found on this new agent only. I am using the nodejs plugin in my tools. I manually checked that npm is available on my new agent. When ssh'ing to the agent, which npm gave the path of /home/jenkins_user/.nvm/versions/node/v14.16.1/bin/npm. This is the case for all my agents. However, when putting sh 'which npm' in the steps for each of the parallel stages, the working nodes return /home/jenkins_user/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_14.10.1/bin/npm, and the non-working node returns nothing, and the stage fails there.

Just to be sure, I added this path to the tool locations in "Node Properties" in the jenkins UI:

enter image description here

The error persists. I checked that Jenkins is using the same credentials for all agents, and those credentials indeed work. Why is Jenkins not finding npm? Is this a problem with Jenkins? With my agent? I'm struggling to find the disconnect here.

0 Answers
Related