作为服务安装时在 Windows 上重新定位 JENKINS_HOME

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28034663/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:55:16  来源:igfitidea点击:

Relocating JENKINS_HOME on Windows when installed as service

windowsjenkins

提问by cod3monk3y

To free up space on C:, I would like to move my Jenkins data files (specifically the \jobsdirectory) from the default installation directory C:\Program Files (x86)\Jenkinsto F:\Jenkins\home. I thinkwhat I need to do is set the JENKINS_HOMEenvironment variable to F:\Jenkins\home. But no matter what I try, the JENKINS_HOMEenvironment variable is always set to the location of jenkins.exe.

为了释放 上的空间C:,我想将我的 Jenkins 数据文件(特别是\jobs目录)从默认安装目录移动C:\Program Files (x86)\JenkinsF:\Jenkins\home. 我我需要做的是将JENKINS_HOME环境变量设置为F:\Jenkins\home. 但无论我尝试什么,JENKINS_HOME环境变量始终设置为jenkins.exe.

Related:

有关的:

Here is what I've tried so far:

这是我迄今为止尝试过的:

  1. Moved jenkins datato F:\Jenkins\home
  2. Stop the running jenkins service
  3. Uninstall the jenkins service with jenkins.exe uninstall
  4. Uninstall jenkins
  5. Delete %HOMEPATH%\.jenkinsdirectory
  6. Delete old jenkins install directory
  7. Download latest MSI installer v1.597
  8. Installed to C:\Program Files (x86)\Jenkins2(renamed to ensure there are no stale values in the registry or config files)
  9. Set system-level environment variable JENKINS_HOMEto F:\Jenkins\home
  10. Set user-level environment variable JENKINS_HOMEto F:\Jenkins\home
  11. Modified jenkins.xmlto use <env name="JENKINS_HOME" value="F:\Jenkins\home"/>
  12. Started the Jenkins service
  1. 将詹金斯数据移至 F:\Jenkins\home
  2. 停止正在运行的詹金斯服务
  3. 卸载 jenkins 服务 jenkins.exe uninstall
  4. 卸载詹金斯
  5. 删除%HOMEPATH%\.jenkins目录
  6. 删除旧的 jenkins 安装目录
  7. 下载最新的 MSI 安装程序 v1.597
  8. 安装到C:\Program Files (x86)\Jenkins2(重命名以确保注册表或配置文件中没有陈旧的值)
  9. 将系统级环境变量设置JENKINS_HOMEF:\Jenkins\home
  10. 将用户级环境变量设置JENKINS_HOMEF:\Jenkins\home
  11. 修改jenkins.xml后使用<env name="JENKINS_HOME" value="F:\Jenkins\home"/>
  12. 启动Jenkins服务

At this point, when I look at the system configuration, JENKINS_HOMEis set to C:\Program Files (x86)\Jenkins2. So it seems it must alwaysbe set to the location of jenkins.exe.

此时,当我查看系统配置时,JENKINS_HOME设置为C:\Program Files (x86)\Jenkins2. 所以它似乎必须始终设置为jenkins.exe.

Maybe I've answered my own question. I'd like to have the program and data separate, if possible. Do I have to install jenkins to my F:\drive? Or, is there a way to simply split off the jobsdirectory and leave everything else on C:?

也许我已经回答了我自己的问题。如果可能,我希望将程序和数据分开。我是否必须将 jenkins 安装到我的F:\驱动器上?或者,有没有办法简单地拆分jobs目录并保留其他所有内容C:

Thanks!

谢谢!

EDIT: I did nothave to move JENKINS_HOME, but instead was able to configure the workspaceand buildsdirectories, which moved all the heavy disk usage over to F:. The settings I chose were:

编辑:我不必移动JENKINS_HOME,而是能够配置工作区构建目录,这将所有大量磁盘使用移至F:. 我选择的设置是:

Workspace Root Directory = F:/Jenkins/workspace/${ITEM_FULLNAME}Build Record Root Directory = F:/Jenkins/jobs/${ITEM_FULL_NAME}/builds

工作区根目录 =F:/Jenkins/workspace/${ITEM_FULLNAME}构建记录根目录 =F:/Jenkins/jobs/${ITEM_FULL_NAME}/builds

I manually migrated these directories so they would not have to be recreated. During this process I did lose my build history, but I'm okay with that for now.

我手动迁移了这些目录,因此不必重新创建它们。在这个过程中,我确实丢失了我的构建历史,但我现在可以接受。

采纳答案by Jeanne Boyarsky

Pre Jenkins 2.121

詹金斯前 2.121

JENKINS_HOME is where Jenkins is installed which is not what you want to change. After you start up Jenkins, go to:

JENKINS_HOME 是 Jenkins 的安装位置,这不是您想要更改的位置。启动 Jenkins 后,转到:

  1. Manage Jenkins
  2. System Configuration
  3. Click the first "advanced" button
  1. 管理詹金斯
  2. 系统配置
  3. 单击第一个“高级”按钮

This gives you text fields where you can change the directory for the workspace and builds directories. Those are the two directories that use a good bit of disk space. Note that it will not move history. If you want to move the existing workspaces/etc, you'll need to manually copy them over.

这为您提供了文本字段,您可以在其中更改工作区的目录并构建目录。这是使用大量磁盘空间的两个目录。请注意,它不会移动历史记录。如果要移动现有的工作区/等,则需要手动复制它们。

Post 2.121You have to set properties (not through the UI). The system property to use is jenkins.model.Jenkins.buildsDir.

Post 2.121你必须设置属性(不是通过 UI)。要使用的系统属性是 jenkins.model.Jenkins.buildsDir。

https://jenkins.io/doc/upgrade-guide/2.121/#ui-option-for-custom-builds-and-workspace-directories-on-the-master-has-been-removedhttps://wiki.jenkins.io/display/JENKINS/Features+controlled+by+system+properties

https://jenkins.io/doc/upgrade-guide/2.121/#ui-option-for-custom-builds-and-workspace-directories-on-the-master-has-been-removed https://wiki。 jenkins.io/display/JENKINS/Features+controlled+by+system+properties

回答by SpaceMonkey13

Another possibility is to move the entire contents of $JENKINS_HOME.

另一种可能性是移动 $JENKINS_HOME 的全部内容。

It does not require editing configuration files, and it preserves the build history.

它不需要编辑配置文件,它保留了构建历史。

  1. Stop the running service: jenkins.exe stop

  2. Uninstall the service: jenkins.exe uninstall

  3. Copy C:\Jenkins\home to F:\Jenkins\home

  4. Rename C:\Jenkins to something else, keep it as backup.

  5. Go to F:\Jenkins\home

  6. Reinstall the service: jenkins.exe install

  7. Start Jenkins: jenkins.exe start

  1. 停止正在运行的服务: jenkins.exe stop

  2. 卸载服务: jenkins.exe uninstall

  3. 将 C:\Jenkins\home 复制到 F:\Jenkins\home

  4. 将 C:\Jenkins 重命名为其他名称,保留作为备份。

  5. 转到 F:\Jenkins\home

  6. 重新安装服务: jenkins.exe install

  7. 启动詹金斯: jenkins.exe start

Enjoy the new disk space!

享受新的磁盘空间!

回答by Bernard

For Jenkins 2.0, it was only necessary to add a system environment variable called "JENKINS_HOME" that points to the new location. The steps I used:

对于 Jenkins 2.0,只需要添加一个名为“JENKINS_HOME”的指向新位置的系统环境变量。我使用的步骤:

  1. Stop the container hosting Jenkins (e.g. Tomcat).
  2. Add a system environment variable called "JENKINS_HOME" that points to the new location.
  3. Restart the container hosting Jenkins.
  1. 停止托管 Jenkins(例如 Tomcat)的容器。
  2. 添加一个名为“JENKINS_HOME”的系统环境变量,指向新位置。
  3. 重新启动托管 Jenkins 的容器。

回答by user2125117

If you are using jenkins version older than 2.0 than you should do following:

如果您使用的 jenkins 版本早于 2.0,则应执行以下操作:

1) open jenkins -> manage Jenkins -> Configure System. Check the path of your Home Directory. 2) Stop the jenkins service. 3) copy the jenkins home directory to other drive or location you want to move. 4) open jenkins.xml from program files and modify the value <env name="JENKINS_HOME" value="d:\Jenkins"/>Change the d:\Jenkins to your new path. 5) restart the Jenkins service. 6) test your job :)

1) 打开 jenkins -> 管理 Jenkins -> 配置系统。检查主目录的路径。2)停止詹金斯服务。3) 将 jenkins 主目录复制到您要移动的其他驱动器或位置。4) 从程序文件中打开 jenkins.xml 并修改值<env name="JENKINS_HOME" value="d:\Jenkins"/>将 d:\Jenkins 更改为您的新路径。5)重启Jenkins服务。6)测试你的工作:)

回答by eckes

Stumbled upon this question because I was short on HDD on C:/ but had plenty on D:/.

偶然发现这个问题是因为我在 C:/ 上缺少硬盘,但在 D:/ 上有很多。

The answer of Jeanne Boyarskyhad exactly zero effect on my Jenkins. Although I changed the two variables, Jenkins still used the original workspaceand jobsdirectories which consumed 1/3 of my C:/ drive.

Jeanne Boyarsky 的回答对我的 Jenkins 的影响完全为零。尽管我更改了这两个变量,但 Jenkins 仍然使用占用了我 C:/ 驱动器 1/3的原始目录workspacejobs目录。

A colleague pointed me to the dead easy solution of simply using Symbolic Linksfor the directories.

一位同事向我指出了简单地对目录使用符号链接的简单解决方案。

After shutting down Jenkins, open your CMDon the %JENKINS_HOME%directory and simply create two links for the big directories:

关闭 Jenkins 后,打开您CMD%JENKINS_HOME%目录并为大目录创建两个链接:

pushd %JENKINS_HOME%
:: save the old directories
ren workspace workspace.old
ren jobs jobs.old
:: now create the links
mklink /D /J workspace D:\jenkins\workspace
mklink /D /J jobs D:\jenkins\jobs
:: copy the original jobs to the new location
xcopy jobs.old\* jobs\ /sy

After this, restart your Jenkins. If everything works fine, you can safely delete the .olddirectories.

在此之后,重新启动您的 Jenkins。如果一切正常,您可以安全地删除.old目录。

回答by Khader Basha Naguri

first set the jenkins home path and then run /install jenkins.war

首先设置 jenkins 主路径,然后运行 ​​/install jenkins.war

example :

例子 :

set JENKINS_HOME=D:\
java -jar jenkins.war --httpPort=8091 -path=D:\<some-folder-name>\

回答by Tagman

Having the same problem and not wanting to change the whole %JENKINS_HOME%location, I came across the answer by adil ameen

%JENKINS_HOME%遇到同样的问题并且不想改变整个位置,我遇到了adil ameen答案

Modify the config.xmlfile in %JENKINS_HOME%(typical under C:\Program Files (x86)\Jenkins). Change <workspaceDir>and <buildsDir>to your desired folder.

修改config.xml文件%JENKINS_HOME%(通常在 C:\Program Files (x86)\Jenkins 下)。更改<workspaceDir><buildsDir>到您想要的文件夹。

You can use the following placeholders: ${JENKINS_HOME}, ${ITEM_ROOTDIR}, ${ITEM_FULL_NAME}. As specified at Features controlled by system propertiesunder jenkins.model.Jenkins.buildsDir

您可以使用以下占位符:${JENKINS_HOME}${ITEM_ROOTDIR}${ITEM_FULL_NAME}。如在指定由系统性能特征控制jenkins.model.Jenkins.buildsDir

Mine looks like this:

我的看起来像这样:

  <workspaceDir>D:/jenkins/jobs/${ITEM_FULL_NAME}/workspace</workspaceDir>
  <buildsDir>D:/jenkins/jobs/${ITEM_FULL_NAME}/builds</buildsDir>

Reload the configuration through the Jenkins UI via Jenkins-> Manage Jenkins-> Reload configuration from disk

通过 Jenkins UI 通过Jenkins-> Manage Jenkins->重新加载配置Reload configuration from disk

You can even keep your build history if you copy the old jobs to the new location.

如果将旧作业复制到新位置,您甚至可以保留构建历史记录。