1

I have a pipeline created in Jenkins with the following configuration for a Nodejs application:

pipeline {
agent any
stages {
    stage('Build') {
        steps {
            nodejs(nodeJSInstallationName: 'Node8') {
                sh 'npm install'
            }
        }
    }
    stage('Test') {
        steps {
            nodejs(nodeJSInstallationName: 'Node8') {
                sh 'npm run test'
            }
        }
    }
    stage('Deploy') {
        steps {
            nodejs(nodeJSInstallationName: 'Node8') {
                sh 'npm run start'
            }
        }
    }
}

}

But the execution of 'npm' is failing, which gives me the following error:

+ npm install
/usr/bin/env:'node': No such file or directory

I installed Jenkins on my server using Docker (image jenkins/jenkins:lts) and I installed the NodeJS plugin in Jenkins.

I created the Node tooling in this way:

enter image description here

Do you know what may be happening?

A greeting.

Jose Sabater
  • 83
  • 4
  • 13
  • How did you installed nodejs inside jenkins container? – Nuwan Attanayake Jul 16 '18 at 12:04
  • I just added it to the post. I did not manually install Node on the Jenkins machine, but I installed the NodeJS plugin for Jenkins. – Jose Sabater Jul 16 '18 at 12:10
  • I guess you have to use the [`tool`](https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#-tool-%20use%20a%20tool%20from%20a%20predefined%20tool%20installation) step to first install the tool. – StephenKing Jul 16 '18 at 13:35
  • I have already installed the NodeJS plugin and I have added an installation to use in the pipeline (Node8) from the section of the Global Tool Configuration menu. Do you need to do something else? – Jose Sabater Jul 17 '18 at 09:50
  • same issue! any luck here @JoseSabater? you can try the scripted pipeline in the meantime https://wiki.jenkins.io/display/JENKINS/NodeJS+Plugin#NodeJSPlugin-Pipeline – Theo Jul 17 '18 at 13:39
  • I have not managed to solve it yet @Theo. If you find the solution share it here, please. Thanks – Jose Sabater Jul 18 '18 at 07:07
  • No luck buddy :( https://stackoverflow.com/questions/51416409/jenkins-env-node-no-such-file-or-directory – Theo Jul 19 '18 at 07:11
  • @JoseSabater check my answer here https://stackoverflow.com/questions/51416409/jenkins-env-node-no-such-file-or-directory/51643415#answer-51643415 maybe we have the same case – Theo Aug 01 '18 at 23:10

2 Answers2

1

Try this

sudo ln -sf "$(which node)" /usr/bin/node

Saagar
  • 794
  • 3
  • 20
  • 41
0

sudo ln -s /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/bin/node /usr/bin/node