[英]How to configure Maven installation in Jenkins per individual Slave node?
If I create a Maven job in Jenkins ( New Item => Maven project , using the maven plugin) with all defaults and run it, I get this error:如果我在 Jenkins(新项目=> Maven 项目,使用 Maven 插件)中使用所有默认值创建一个 Maven 作业并运行它,我会收到此错误:
Started by user anonymous
Building on master in workspace /var/lib/jenkins/jobs/job_name/workspace
ERROR: A Maven installation needs to be available for this project to be built.Either your server has no Maven installations defined, or the requested Maven version does not exist.
Finished: FAILURE
Maven runs perfectly from command line with just mvn
. Maven 只需使用
mvn
从命令行完美运行。
There is a system-wide Jenkins configuration for Maven installation: Manage Jenkins => Configure System => Maven / Maven installations . Maven 安装有一个系统范围的 Jenkins 配置:管理 Jenkins =>配置系统=> Maven / Maven 安装。 And if I add Maven installation using this web UI (by providing pre-installed path in
MAVEN_HOME
as /usr/share/maven
), the job runs SUCCESSFULLY.如果我使用此 Web UI 添加 Maven 安装(通过在
MAVEN_HOME
提供预安装的路径作为/usr/share/maven
),该作业将成功运行。
The global Jenkins config does not make sense: Maven is run per Slave, not per Jenkins.全局 Jenkins 配置没有意义:Maven 是每个 Slave 运行的,而不是每个 Jenkins 运行的。
The zoo of Slaves where Jenkins runs jobs may contain Slaves with various platforms, OSes, environments where different versions of Maven are installed in different locations. Jenkins 运行作业的 Slaves 动物园可能包含具有各种平台、操作系统、不同版本 Maven 安装在不同位置的环境的 Slaves。
Setting environment variables like MAVEN_HOME
and M2_HOME
to the same path for entire system on Slave node didn't work.将
MAVEN_HOME
和M2_HOME
等环境变量设置为 Slave 节点上整个系统的相同路径不起作用。
Both Jenkins Master and Slave are Linux hosts. Jenkins Master 和 Slave 都是 Linux 主机。 Jenkins version:
1.598
詹金斯版本:
1.598
Assuming you have Java and Maven installed on your slave:假设您的从站上安装了 Java 和 Maven:
It should now work (even if you have configured a Maven installation on the master).它现在应该可以工作了(即使您已经在 master 上配置了 Maven 安装)。
For me, the solution was to go to Manage Jenkins -> Global Tool Configuration, and set up maven there.对我来说,解决方案是转到 Manage Jenkins -> Global Tool Configuration,然后在那里设置 maven。 You can access this via /configureTools (ex: http://your-ip:8080/jenkins/configureTools )
您可以通过 /configureTools 访问它(例如: http://your-ip:8080/jenkins/configureTools )
Example: Maven installations示例:Maven 安装
Additional configurations for other common tools at /configureTools : /configureTools 中其他常用工具的其他配置:
Git installations Git 安装
JDK installations JDK 安装
If you do NOT add Maven to the Master configuration and you just install it on every slave with their own possibly different environment variables (example with version 3.2.5)如果您没有将 Maven 添加到 Master 配置中,并且您只是将它安装在每个具有可能不同的环境变量的从属设备上(例如版本 3.2.5)
M2_HOME=C:\apache-maven-3.2.5
M2=C:\apache-maven-3.2.5\bin
Path+=;C:\apache-maven-3.2.5\bin
then every Jenkins slave will just use Maven with local settings.那么每个 Jenkins slave 都会使用 Maven 和本地设置。
To make it simple, just use my public docker image为了简单起见,只需使用我的公共 docker 镜像
docker push chiraggupta95/jenkinswithmvn:v1
In case you want to customize your own image, just check out my git repo for complete instructions.如果您想自定义自己的图像,只需查看我的 git repo 以获取完整说明。
https://github.com/chiraggupta95apr/jenkins
Happy Coding :)快乐编码:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.