0
votes

I am trying to setup CI/CD pipeline for my node.js application with Jenkins.

What I am trying to do is login to my application server through jenkins and execute the commands on the server with the help of publish over ssh plugin (https://wiki.jenkins.io/display/JENKINS/Publish+Over+SSH+Plugin).

I've selected the Send Files or Execute commands over SSH option and added the following commands in Exec command section.

cd <project-folder> && git pull origin master && npm install

I am getting an error like npm not found but I try to directly on the server there is no error.

So I believe there's is a permission issue on jenkins but i can't find the solution

1
This might also be a path issue, try to add sh 'env' to print the current environment variables. - Dominik Gebhart

1 Answers

0
votes

Yes, you identified the issue correctly ... Its permission issue .. I assume you have already added the root login details at "SSH remote hosts" in the "configure system" section of the jenkins.

  • First pull the GIT repo to the jenkins workspace via web hook settings in github. Hope you have succeeded in this step also

In "Build Environment" select "Execute shell script on remote host using ssh" then use the following

cd <project-folder>  (Ex: cd /var/lib/jenkins/workspace/<project-folder>)

npm install 

NOTE: you should give the complete server path in the server to avoid permission .. If you are working with localhost then it may work and other very important when you use "Execute shell script on remote host using ssh" you should access via root user only NOT with the cpanel account login.. This will avoid permissions issue.

Once the NPM is install, check the console log for "success" Then do the other commands and suggest to remove the "npm install" as installation multiple times will increase the application compiling time..