如何在詹金斯中以root身份执行命令

时间:2019-10-03 09:18:11

标签: jenkins

我正在使用jenkins进行作业,我想以root身份在execute shell中执行命令,但是当我运行时 sudo su,然后whoami我得到结果ubuntu。无论如何,我可以以root用户身份运行命令吗?

1 个答案:

答案 0 :(得分:1)

我假设您已经在sudo用户组中添加了Jenkins,如果没有,则添加此jenkins ALL=(ALL) NOPASSWD: ALL

Is it possible to allow jenkins to access the files that only root or some specific programs have access to?

sudo su将不起作用,因为Jenkins将命令作为脚本运行,您必须选择

  • 内联sudo用户命令
  • 创建脚本,然后使用sudo user
  • 运行

sudo su - root -c 'whoami'

enter image description here enter image description here

或将命令保存到bash脚本,然后使用sudo运行。

sudo /path_to_command.sh