如何将路径变量添加到作业外壳
我正在设置 Jenkins 来替换我们当前的 TeamCity CI 构建。
我创建了一个自由风格的软件项目,以便我可以执行 shell 脚本。 Shell 脚本运行 mvn 命令。
但构建失败,抱怨找不到“mvn”命令。
我认为这是因为 Jenkins 在不同的 shell 中运行构建,而该 shell 的路径上没有 Maven。
我的问题是;如何添加路径以便在 Shell 脚本中找到“mvn”?我环顾四周,但找不到合适的地方。
感谢您抽出时间。
I am setting up Jenkins to replace our current TeamCity CI build.
I have created a free-style software project so that I can execute a shell script.
The Shell script runs the mvn command.
But the build fails complaining that the 'mvn' command cannot be found.
I have figured that this is because Jenkins is running the build in a different shell, which does not have Maven on it's path.
My question is; how do I add the path so 'mvn' is found in my Shell script? I've looked around but can't spot where the right place might be.
Thanks for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我通过导出并设置 Jenkins 作业配置中的路径解决了这个问题,您可以在其中输入 shell 命令。因此,我在执行 Shell 脚本之前设置了环境变量,效果很好。
I solved this by exporting and setting the Path in the Jenkins Job configuration where you can enter shell commands. So I set the environments variable before I execute my Shell script, works a treat.
一些可能的解决方案:
ps:通常
/bin/sh
是从詹金斯,如果你想要切换到例如。 bash,如果你想配置全局环境变量,你可以在 jenkins 系统设置中配置它。Some possible solutions:
ps.: Usually
/bin/sh
is chosen from Jenkins, if you want to switch to eg. bash, you can configure this in the jenkins system settings, in case you want to configure global environment variables.您可以使用 envInject 插件。它非常强大。
我用它来安装 rbenv。它可以将环境变量注入到您当前的工作中。
You can use envInject plugin. It's very powerful.
I use it to install rbenv. And it can inject environment variables into your current job.
Dags 建议的另一个选择是,如果您只使用单个版本的 Maven,则在每个从属服务器上您可以执行以下任一操作:
* 添加 PATH=${PATH}:
* 将 mvn 符号链接到 /usr/bin 中; sudo ln -s /usr/bin
我现在不在 Jenkins 盒子里,但如果您愿意,我可以找到一些更详细的示例。
Another option to Dags suggestion is that if you're only using a single version of maven, on each slave server you could do either;
* add PATH=${PATH}:
* symlink mvn into /usr/bin with; sudo ln -s /usr/bin
I'm not at a Jenkins box at the moment, but I can find some more detailed examples if you'd like.
Jenkins 默认使用 sh 而不是 bash。
这是我第一次定义 jenkins maven 作业,我还遵循了一些常规的 maven 指令(用于从命令行运行...),并尝试使用 M2_HOME、M2、PATH 更新 ~/.bashrc,但它没有工作是因为詹金斯使用 sh 而不是 bash。然后我发现jenkins内置了一种更简单更好的方法。
安装maven后,我应该在jenkins中配置我的maven安装。
要在 Jenkins 中配置 Maven 安装:
b.并在MVN_HOME下设置maven的安装路径,例如“/usr/local/apache-maven/apache-maven-3.0.5”
定义作业使用 Maven 目标
Jenkins is using sh by default and not bash.
This is my first time defining a jenkins maven job, and I also followed soem regular maven instructions (for running from command line...), and tried to update ~/.bashrc with M2_HOME, M2, PATH, but it didn't work because jenkins used sh and not bash. Then I found out that there is a simpler and better way built into jenkins.
After installing maven, I was supposed to configure my maven installation in jenkins.
To configure your maven installation in Jenkins:
b. and under MVN_HOME set the path to where you installed maven, for example "/usr/local/apache-maven/apache-maven-3.0.5"
Define a job with maven target