Java Jenkins 存储库位置

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

Jenkins repository location

javamavenjenkins

提问by Mital Pritmani

This might be a weird question but this is happening to me. Can anyone tell me whice repository location does Jenkins use when we are building a Maven project? I have chosen Default (~/.m2/repository)option while configuring Jenkins but it seems the behavior is a bit different. Though there is this myown.jar present in my local repository i.e. in /home/username/.m2, it shows the error that myown.jar is not found. So I have to build a job for this myownproject, build it and then the error gets solved.

这可能是一个奇怪的问题,但这发生在我身上。谁能告诉我在构建 Maven 项目时 Jenkins 使用哪个存储库位置?我Default (~/.m2/repository)在配置 Jenkins 时选择了选项,但行为似乎有点不同。虽然在我的本地存储库中存在这个 myown.jar,即在 中/home/username/.m2,但它显示未找到 myown.jar 的错误。所以我必须为这个myown项目构建一个工作,构建它然后错误得到解决。

Not only this, when I put the Jenkins script in startup i.e. /usr/bin/java -jar <warpath>.war, it downloaded all the dependencies of my projects again while building it, though I had built the configured project 5 times before putting the script in startup !! Isn't it weird behavior? Which repository location does Jenkins use? Or is there something what I might be missing?

不仅如此,当我将 Jenkins 脚本放入启动 ie 时/usr/bin/java -jar <warpath>.war,它在构建它时再次下载了我项目的所有依赖项,尽管在将脚本放入启动之前我已经构建了配置的项目 5 次!!这不是奇怪的行为吗?Jenkins 使用哪个存储库位置?或者有什么我可能会遗漏的吗?

回答by Jorge_B

It should be using whatever you have configured in /home/username/.m2/settings.xml- remember usernamewill be the one effectively executing the jenkins server. However, if your current maven version has some settings.xml in its /conf directory, that one is prioritary compared to the one in your /home

它应该使用您配置的任何内容/home/username/.m2/settings.xml- 请记住用户名将是有效执行 jenkins 服务器的用户名。但是,如果您当前的 maven 版本在其 /conf 目录中有一些 settings.xml,则与 /home 中的相比,该版本具有优先级

Once you find (or create) that settings.xml, make it point to wherever you need to have your local repository

找到(或创建)该 settings.xml 后,将其指向您需要拥有本地存储库的任何位置

回答by Martin Ellis

By default, Jenkins will use the local repository ~/.m2/repository under the user account used to run Jenkins.

默认情况下,Jenkins 将使用用于运行 Jenkins 的用户帐户下的本地存储库 ~/.m2/repository。

It can be configured to use a private repository for a build, but it sounds as though you haven't configured that.

它可以配置为使用私有存储库进行构建,但听起来好像您还没有配置它。

When I put the Jenkins script in startup i.e. /usr/bin/java -jar .war, it downloaded all the dependencies of my projects again while building it, though I had built the configured project 5 times before putting the script in startup

当我将 Jenkins 脚本放在启动时,即 /usr/bin/java -jar .war 时,它在构建它时再次下载了我项目的所有依赖项,尽管在将脚本启动之前我已经构建了 5 次配置的项目

From this, it sounds as though your startup script might be running as a different user? Perhaps the rootuser?

由此看来,您的启动脚本可能以不同的用户身份运行?也许是root用户?

Running Jenkins as root would cause it to use a different local repository, i.e. /root/.m2/repository. You might check whether there is a Maven repository there, and if so, ensure that Jenkins is never run as root.

以 root 身份运行 Jenkins 会导致它使用不同的本地存储库,即/root/.m2/repository. 您可以检查那里是否有 Maven 存储库,如果有,请确保 Jenkins 永远不会以 root 身份运行。

回答by Mark O'Connor

I suggest using configuration file provider pluginto manage Maven settings.

我建议使用配置文件提供程序插件来管理 Maven 设置。

The plugin allows configuration files to managed via the Jenkins UI and easily selected for each Maven project build.

该插件允许通过 Jenkins UI 管理配置文件,并为每个 Maven 项目构建轻松选择。

回答by Greesh Kumar

actually it depends on configuration of each individual maven project. By default, Jenkins will use the local repository JENKINS_HOME_DIR/.m2/repositoryif you install the maven by ticking the Install automatically checkbox, otherwise it will use the local /home/username/.m2/repository.

实际上这取决于每个单独的 Maven 项目的配置。默认情况下,JENKINS_HOME_DIR/.m2/repository如果您通过勾选自动安装复选框来安装 Maven ,Jenkins 将使用本地存储库,否则它将使用本地 /home/username/.m2/repository。

however you can change this default location by setting up the settings.xml file in ~/.m2/settings.xml

但是,您可以通过在 ~/.m2/settings.xml 中设置 settings.xml 文件来更改此默认位置

OR

或者

for global use you can change it from jenkins_home_dir/conf

对于全球使用,您可以从 jenkins_home_dir/conf 更改它

for example if you install maven by tick Install automatically checkbox

例如,如果您通过勾选自动安装复选框来安装 maven

Step1.Choose the maven Installation for a particular project in jenkins home directory

Step1.在 jenkins 主目录中为特定项目选择 maven 安装

$ cd Jenkins_home_dir/tools/hudson.tasks.Maven_MavenInstallation/

Step 2.change the localRepository in settings.xml

Step 2.更改 settings.xml 中的 localRepository

The hierarchy for settings.xml is user .m2directory and if it could not find that, it will try to find the one in {maven home}/conf/settings.xml.

settings.xml 的层次结构是用户.m2目录,如果找不到,它将尝试在 .xml 中找到{maven home}/conf/settings.xml

回答by prayagupd

On unix system use findtool,

在unix系统上使用find工具,

[root@ip-172-23-38-167 ~]# sudo find / -name ".m2"
/root/.m2
/var/lib/jenkins/.m2

Its under /var/lib/jenkinson rhel, (JENKINS_HOME_DIRsupposed to be /var/lib/jenkins)

它在/var/lib/jenkinsrhel下,(JENKINS_HOME_DIR应该是/var/lib/jenkins

[root@ip-172-23-38-167 ~]# ll /var/lib/jenkins/.m2/repository/
total 8
drwxr-xr-x.  4 jenkins jenkins   35 Apr 25 00:12 asm
drwxr-xr-x.  3 jenkins jenkins   38 Apr 23 20:18 backport-util-concurrent
drwxr-xr-x.  3 jenkins jenkins   17 Apr 25 00:12 ch
drwxr-xr-x.  3 jenkins jenkins   25 Apr 23 20:17 classworlds
drwxr-xr-x. 23 jenkins jenkins 4096 Apr 25 03:49 com
drwxr-xr-x.  3 jenkins jenkins   25 Apr 23 20:17 commons-cli
drwxr-xr-x.  3 jenkins jenkins   27 Apr 23 20:17 commons-codec
drwxr-xr-x.  3 jenkins jenkins   26 Apr 23 20:17 commons-dbcp
drwxr-xr-x.  3 jenkins jenkins   24 Apr 23 20:18 commons-io
drwxr-xr-x.  3 jenkins jenkins   26 Apr 23 20:18 commons-lang
drwxr-xr-x.  4 jenkins jenkins   56 Apr 24 22:45 commons-logging
drwxr-xr-x.  3 jenkins jenkins   26 Apr 23 20:17 commons-pool
drwxr-xr-x.  3 jenkins jenkins   27 Apr 25 00:11 eventstream
drwxr-xr-x.  6 jenkins jenkins   63 Apr 25 00:29 io
drwxr-xr-x.  6 jenkins jenkins   69 Apr 25 00:11 javax
drwxr-xr-x.  3 jenkins jenkins   19 Apr 24 23:09 jline
drwxr-xr-x.  3 jenkins jenkins   23 Apr 24 23:09 joda-time
drwxr-xr-x.  3 jenkins jenkins   19 Apr 23 20:17 junit
drwxr-xr-x.  3 jenkins jenkins   19 Apr 24 22:45 log4j
drwxr-xr-x.  9 jenkins jenkins  104 Apr 25 00:11 net
drwxr-xr-x.  3 jenkins jenkins   17 Apr 25 00:12 nz
drwxr-xr-x.  3 jenkins jenkins   18 Apr 25 00:12 ognl
drwxr-xr-x. 34 jenkins jenkins 4096 Apr 25 00:12 org
drwxr-xr-x.  3 jenkins jenkins   20 Apr 24 23:09 software
drwxr-xr-x.  3 jenkins jenkins   21 Apr 25 01:47 xmlpull
drwxr-xr-x.  3 jenkins jenkins   22 Apr 25 01:47 xpp3

回答by Sunvic

On Windows, when installed and run as a Windows service, this can default to the below.

在 Windows 上,当作为 Windows 服务安装并运行时,这可以默认为以下内容。

C:\Windows\SysWOW64\config\systemprofile\.m2\repository

C:\Windows\SysWOW64\config\systemprofile\.m2\repository

C:\Windows\System32\config\systemprofile\.m2\repository

C:\Windows\System32\config\systemprofile\.m2\repository

回答by Kamiel Ahmadpour

In Ubuntu, I found the repository location under /var/lib/jenkins/.m2 And I just deleted that one and instead made a link to my existing maven repository ...

在 Ubuntu 中,我在 /var/lib/jenkins/.m2 下找到了存储库位置,我刚刚删除了那个,而是创建了一个指向我现有 Maven 存储库的链接......