简体   繁体   English

Jenkins职位和GIT / Maven

[英]Jenkins jobs and GIT/maven

I want to execute a new task in jenkins. 我想用詹金斯执行一个新任务。

I want to clone a git repository in jenkins workspace. 我想在jenkins工作区中克隆一个git存储库。 This repository has two folders, one for each maven project. 该存储库有两个文件夹,每个maven项目一个。

But, I only have to execute mvn command in one of these folders. 但是,我只需要在这些文件夹之一中执行mvn命令。

How do I do to navegate to correct folder and ejecute a mvn command in jenkins? 如何导航到正确的文件夹并在jenkins中弹出mvn命令?

I have checked "Consult repository (SCM)" option and I try to execute a shell script previously to run mvn command like that: 我已经选中了“咨询存储库(SCM)”选项,并且我尝试先执行Shell脚本来运行mvn命令,如下所示:

cd $WORKSPACE/CompositeApplicationExampleProject/

But I get this error: 但是我得到这个错误:

[pruebaJenkins] $ /bin/sh -xe /clinker/jenkins/temp/hudson5899551334803596574.sh 
+ cd /clinker/jenkins/data/workspace/pruebaJenkins/CompositeApplicationExampleProject/
/clinker/jenkins/temp/hudson5899551334803596574.sh: 2: cd: can't cd to/clinker/jenkins/data/workspace/pruebaJenkins/CompositeApplicationExampleProject/
Build step 'Execute shell' marked build as failureFinished: 
FAILURE

Generally - having this kind of setup (multiple maven project in one git repository) is bad practice - especially when using jenkins. 通常-进行这种设置(在一个git仓库中有多个Maven项目)是不好的做法-特别是在使用jenkins时。 I need to deal with a big project that sadly uses this pattern and the experience is not one I would like to repeat. 我需要处理一个可悲的使用这种模式的大型项目,而这种经历并不是我想重复的。

Solution for your problem: Just add 2 maven jobs (install the plugin if not already done) and add the pom path under the build section of the respective job configuration. 解决您的问题的方法:只需添加2个maven作业(如果尚未完成,则安装插件),然后在相应作业配置的build部分下添加pom路径。 Example: 例:

project_folder_1/pom.xml

If you want to build only when changes occur in the respective directory this is tricky and needs some tweaks in the git configuration of the job. 如果仅在各个目录中发生更改时才构建,则这很棘手,并且需要在作业的git配置中进行一些调整。 You can use the additional behaviour "Polling ignores commits in certain paths". 您可以使用其他行为“轮询忽略某些路径中的提交”。 But be aware that this does not work all the time due to bugs in the git plugin. 但是请注意,由于git插件中的错误,这种方法并非始终有效。

You don't need to change directory at all. 您根本不需要更改目录。

Maven have a parameter file (or f for short) to specify custom pom.xml, for example: Maven有一个参数file (或简称f )来指定自定义pom.xml,例如:

mvn -file dir1/dir2/pom.xml package

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM