I have added the jenkins user to had all permission.
jenkins ALL=(ALL) NOPASSWD: ALL
also installed the pm2
as globally, and pm2
need to run command
sudo npm start
as build process needs to create some directory, if I run sudo npm start
in the app1 directory it works perfectly however with pm2 command it throws access error
sudo pm2 start config.js
config.js
module.exports = {
apps : [{
name : "app1",
cwd : "./my-dir/app1,
script : "sudo npm",
args : "start"
},{
name : "app2",
cwd : "./my-dir/app2",
script : "npm",
args : "start"
}]
}
Is it error with pm2 permission or user permission?
Instead of running the command with all the sudo
privileges create the user with the least number of privileges that you want to give to your app.
You already have the jenkins set to use sudo
with no password, so you can use the below command to run the pm2
from jenkins as other user with least privilege.
sudo su - username -c 'pm2 start config.js'
The above command will be run as the specified user