在 Linux 上以用户身份运行 Jenkins 作业
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8910075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run Jenkins jobs on Linux under a User
提问by 7dr3am7
I have Jenkins installed in Linux and I want to run the build(s) under a user.
我在 Linux 中安装了 Jenkins,我想在用户下运行构建。
Not just a simple user, but one that belongs to the list of user that access the linux machine and that belongs to a certain group as it has privileges to modify/create files under a certain folder.
不仅仅是一个简单的用户,而是属于访问 linux 机器的用户列表并且属于某个组,因为它有权在某个文件夹下修改/创建文件。
I have read somewhere that you can set the variable $JENKINS_USER but I do not know where and how. Thank you for your time
我在某处读到您可以设置变量 $JENKINS_USER 但我不知道在哪里以及如何设置。感谢您的时间
P.S. I did some research all the questions posted are similar but not the same as this one
PS我做了一些研究发布的所有问题都相似但与这个问题不同
Please if I am not clear read this: Usually Jenkins execute the build using a user called jenkins, now I want to be able to use a different user (pre-existing).
如果我不清楚,请阅读:通常 Jenkins 使用名为 jenkins 的用户执行构建,现在我希望能够使用不同的用户(预先存在)。
采纳答案by Peter Schuetze
Have a look at the Started-By Environment Variable plugin.
看看 Started-By Environment Variable 插件。
https://wiki.jenkins-ci.org/display/JENKINS/Started-By+Environment+Variable+Plugin
https://wiki.jenkins-ci.org/display/JENKINS/Started-By+Environment+Variable+Plugin
EDIT:
编辑:
If you are just asking how to set up Jenkins to run under a different user in Linux it depends on how you installed it. I never set up Jenkins on Linux yet (but I can use google). Have a look at https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkinsfor different setup options. I had a look at Installing Jenkins as a Unix daemonand at step 7 you need to setup a configuration file. Change the last line in that file (RUN_AS_USER=jenkins
) to contain the user of your choice.
如果您只是询问如何设置 Jenkins 在 Linux 中的不同用户下运行,则取决于您如何安装它。我从未在 Linux 上设置 Jenkins(但我可以使用谷歌)。查看https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins了解不同的设置选项。我查看了将Jenkins 安装为 Unix 守护进程,在第 7 步中您需要设置一个配置文件。更改该文件中的最后一行 ( RUN_AS_USER=jenkins
) 以包含您选择的用户。
回答by Gangnus
Yes, it is necessary to set JENKINS_USER variable, but in another file.
是的,有必要设置 JENKINS_USER 变量,但在另一个文件中。
Look here http://blog.manula.org/2013/03/running-jenkins-under-different-user-in.html
看这里http://blog.manula.org/2013/03/running-jenkins-under-different-user-in.html
回答by bohr
There is nothing only the root user could do that you cant do in a proper way, by creating a dedicated user for your task with proper rights on the concerned files or binaries. Give example of the task you want to do as root if you need more accurate example.
通过为您的任务创建一个对相关文件或二进制文件具有适当权限的专用用户,没有什么只有 root 用户可以做而您不能以正确的方式做的。如果您需要更准确的示例,请举例说明您希望以 root 身份执行的任务。