Java 为不同的 user.home 配置 Jenkins
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18704247/
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
Configure Jenkins for different user.home
提问by TheDevOpsGuru
I am running Jenkins version 1.527 (I know there is a newer version but it is broken, I can't use the user interface in 1.528 and haven't gotten a chance to upgrade to 1.529)
我正在运行 Jenkins 版本 1.527(我知道有一个更新的版本但它坏了,我无法在 1.528 中使用用户界面,也没有机会升级到 1.529)
I am trying to change the user.home system property in Jenkins by doing this in my startup script:
我试图通过在我的启动脚本中执行此操作来更改 Jenkins 中的 user.home 系统属性:
export HOME=/new-home-dir
However, the environment variable shows correctly in jenkins and user.dir shows as the exported variable, but user.home does not change.
但是,环境变量在 jenkins 中正确显示,并且 user.dir 显示为导出变量,但 user.home 不会更改。
The reason I can't use the default functionality is because I am in an enterprise that locks down the user's home directory and my user can add or modify files there.
我不能使用默认功能的原因是我所在的企业锁定了用户的主目录,我的用户可以在那里添加或修改文件。
Any help on changing user.home would be greatly appreciated.
任何有关更改 user.home 的帮助将不胜感激。
FYI - I am running Jenkins on RHEL v6.2
仅供参考 - 我在 RHEL v6.2 上运行 Jenkins
Attempted Solutions
尝试的解决方案
- add -Duser.home=/newDir to JAVA_OPTS or JAVA_ARGS, neither worked
- add -Duser.home=/newDir to the MAVEN_OPTS in the build job.
- 将 -Duser.home=/newDir 添加到 JAVA_OPTS 或 JAVA_ARGS,均无效
- 将 -Duser.home=/newDir 添加到构建作业中的 MAVEN_OPTS。
采纳答案by Michal
I found another workaroud.
我找到了另一个解决方法。
- Go to the Manage Jenkins > Configure System
- Navigate to the Global Properties
- Make the Checkbox Environment variables active
- Name field pop up the user.home
- value is your desired path
- Click Apply, Save and Restart Jenkins
- 转到管理 Jenkins > 配置系统
- 导航到全局属性
- 使复选框环境变量处于活动状态
- 名称字段弹出user.home
- value 是您想要的路径
- 单击应用、保存并重新启动 Jenkins
This overrides that path.
这将覆盖该路径。
回答by Pmt
I had the same problem and solved in two different ways:
我遇到了同样的问题,并以两种不同的方式解决:
1- At the first time I edited the file startup.sh
, inside /tomcat/bin
. Inside this file I added this at the first line: JENKINS_HOME=/var/jenkins
1-我第一次编辑文件时startup.sh
,里面的/tomcat/bin
. 在这个文件中,我在第一行添加了这个:JENKINS_HOME=/var/jenkins
2- Set the same inside environment variables. Just take care to set the variable with the same user that Jenkins are executed. For example, if Jenkings Jenkins is running under root, you need to specify the environment variable with this uses.
2- 设置相同的内部环境变量。只需注意使用执行 Jenkins 的同一用户设置变量即可。例如,如果 Jenkings Jenkins 在root下运行,则需要使用此用途指定环境变量。
Observation: Because of compatibility questions, if you define HUDSON_HOME
instead of JENKINS_HOME
it will works fine two.
观察:由于兼容性问题,如果您定义HUDSON_HOME
而不是JENKINS_HOME
它会正常工作两个。
Hope it helps!
希望能帮助到你!
回答by Dinesh
I exactly had the same problem. You cannot just add an environment variable to change the path. You'll need to change the jenkins user's home directory itself.
我完全有同样的问题。您不能只添加环境变量来更改路径。您需要更改 jenkins 用户的主目录本身。
In a linux/unix based system run the following command on your terminal.
在基于 linux/unix 的系统中,在终端上运行以下命令。
login as a root user or use sudo in front of the commands if you're not running it as root user,
如果您不是以 root 用户身份运行,请以 root 用户身份登录或在命令前使用 sudo,
1) Move the Jenkins installation directory your desired location.
1) 将 Jenkins 安装目录移动到您想要的位置。
mv /var/lib/jenkins /path/to/your/location
2) Change the Jenkins users home directory.
2) 更改 Jenkins 用户主目录。
usermod -d /path/to/your/location jenkins
Now restart jenkins. You should see the user.home and HOME variable set to the new location.
现在重新启动詹金斯。您应该会看到 user.home 和 HOME 变量设置为新位置。
回答by Rajib Biswas
Changing JENKINS_HOME and user.home are two separate topics. The original questions is all about changing the user.home system property. I resolved this issue (in Jenkins 2.34) by following the steps mentioned below:
更改 JENKINS_HOME 和 user.home 是两个独立的主题。最初的问题都是关于更改 user.home 系统属性的。我按照下面提到的步骤解决了这个问题(在 Jenkins 2.34 中):
- Go to: Manage Jenkins > Configure System
- Check the 'Environment variables' checkbox
- Enter 'user.home' in Name field and your desired user home path in Value field
- Save the changes and you are done In my Jenkins, I was facing the issue that Jenkins maven was trying to read the maven settings.xml from a wrong user.home path. I resolved this issue by adding 'user.home' environment variable in Jenkins as explained above.
- 转到:管理 Jenkins > 配置系统
- 选中“环境变量”复选框
- 在名称字段中输入“user.home”,在值字段中输入所需的用户主路径
- 保存更改并完成在我的 Jenkins 中,我遇到了 Jenkins maven 试图从错误的 user.home 路径读取 maven settings.xml 的问题。我通过在 Jenkins 中添加 'user.home' 环境变量解决了这个问题,如上所述。
回答by Mr.K
I exactly had a same problem on ubuntu server.
我在 ubuntu 服务器上遇到了同样的问题。
login as a root user.
以 root 用户身份登录。
stop the all process running with a jenkins user.
停止与 jenkins 用户一起运行的所有进程。
1) stop the jenkins service.
1)停止詹金斯服务。
sudo service jenkins stop
2) Change the Jenkins users home directory.
2) 更改 Jenkins 用户主目录。
usermod -d /path/to/your/location jenkins
3) start the jenkins service.
3)启动詹金斯服务。
sudo service jenkins start
You will see the user.home and HOME and PWD variable set to the new location.
您将看到 user.home 和 HOME 以及 PWD 变量设置为新位置。
Go to: Manage Jenkins > system information
Here you will see the changed variables location
转到:管理 Jenkins > 系统信息
在这里您将看到更改的变量位置