简体   繁体   English

如何使用 pm2 和 jenkins 运行“sudo npm start”?

[英]How to user pm2 and jenkins to run the 'sudo npm start'?

I have added the jenkins user to had all permission.我已添加 jenkins 用户以拥有所有权限。

jenkins ALL=(ALL) NOPASSWD: ALL

also installed the pm2 as globally, and pm2 need to run command还全局安装了pm2pm2需要运行命令

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由于构建过程需要创建一些目录,如果我在 app1 目录中运行sudo npm start它可以完美运行但是使用 pm2 命令它会抛出访问错误

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?是 pm2 权限还是用户权限错误?

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.不是使用所有sudo权限运行命令,而是创建具有您想要授予应用程序的最少权限的用户。

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没有密码,所以你可以使用以下命令来运行pm2从詹金斯与最小特权其它用户。

sudo su - username -c 'pm2 start config.js'

The above command will be run as the specified user上面的命令将以指定的用户身份运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM