简体   繁体   English

使用git repository和jenkins执行maven发布的子项目

[英]perform maven release of child project using git repository and jenkins

Setup 建立

I have a project with a child project and want to do a maven release of the child (Project B): 我有一个带有子项目的项目,想要对孩子进行maven释放(项目B):

Project-A/
  pom.xml
  Project-B/
    pom.xml
    src/

The folder of Project-A is at the same time my git repository, which I clone from our central git server. Project-A的文件夹同时是我的git存储库,我从我们的中央git服务器克隆。

For our release we use the jenkins as build server with the Jenkins Maven Release Plug-in to start the release build. 对于我们的发布,我们使用jenkins作为构建服务器和Jenkins Maven Release Plug-in来启动发布版本。

So after the jenkins Job (called JobB) is started it will checkout the Project-A folder into the following place: /Users/titan/.jenkins/jobs/JobB/workspace . 因此,在jenkins Job(称为JobB)启动后,它会将Project-A文件夹签出到以下位置: /Users/titan/.jenkins/jobs/JobB/workspace

Due to the way how git is working I can only clone the top level of my structure. 由于git的工作方式,我只能克隆我的结构的顶层。 So this means I need to set the pom I want to build in jenkins to Project-B/pom.xml which then will change the working directory maven uses for doing its work. 所以这意味着我需要将我想要在jenkins中构建的pom设置为Project-B / pom.xml,然后将更改maven用于执行其工作的工作目录。

This creates a lot of issues with git as the maven release plugin tries to commit to the wrong directory (it assumes that Project-A/Project-B/ is a valid git repository). 这会产生很多git问题,因为maven发布插件试图提交到错误的目录(它假定Project-A / Project-B /是一个有效的git存储库)。 I could solve all such issues (by deactivating the pushes to the remote repo when doing the release and specifying the correct scm url when doing the release.) 我可以解决所有这些问题(通过在执行发布时停用推送到远程仓库并在执行发布时指定正确的scm url。)

This is the value of the Release goals and options field in the jenkins JobB configuration: 这是jenkins JobB配置中的Release goals and options字段的值:

-X -DpreparationGoals="clean install" 
-DpushChanges=false 
-DconnectionUrl=scm:git:file:///Users/titan/.jenkins/jobs/JobB/workspace 
release:prepare release:perform

The file url for the connectionUrl is needed because I do not push the changes to the git remote server and the clone which is done at the beginning of maven:perform would not find the tag from which it needs to checkout. 需要connectionUrl的文件URL,因为我没有将更改推送到git远程服务器以及在maven开头执行的克隆:perform将找不到需要签出的标记。

Issue 问题

And after all this here is my issue which I'm not able to solve: 毕竟这是我的问题,我无法解决:

The maven:prepare step runs through and does all its work (changing version numbers in pom, creating release tag). maven:准备步骤贯穿并完成所有工作(更改pom中的版本号,创建发布标记)。 Then the maven:perform step starts, clones the content from the git repository, checkouts tag into the target folder, and then invokes the deploy command. 然后maven:perform步骤启动,将内容从git存储库克隆,checkouts标记到目标文件夹,然后调用deploy命令。

But here is the issue the invoked deploy command is invoked on the top level so it is deploying Project-A instead of the Project-B. 但是这里是在顶层调用调用的deploy命令的问题,因此它正在部署Project-A而不是Project-B。 The job itself is running through without any errors it is just building and deploying the wrong thing. 作业本身正在运行,没有任何错误,它只是构建和部署错误的东西。

Here is the command maven generates to execute the deploy: 以下是maven生成的用于执行部署的命令:

[INFO] Executing goals 'deploy'...
[DEBUG] Using ${maven.home} of: '/usr/share/java/maven-3.0.3'.
[DEBUG] Executing: /bin/sh -c cd /Users/titan/.jenkins/jobs/jobB/workspace/Project-B/target/checkout && /usr/share/java/maven-3.0.3/bin/mvn -B -X -D maven.repo.local=/Users/titan/.m2/repository -s /Users/titan/.m2/settings.xml -D performRelease=true deploy

So it is invoking the pom file inside the checkout directory instead inside checkout/Project-B. 所以它调用checkout目录中的pom文件而不是checkout / Project-B。 Interestingly the maven:prepare step does execute on the correct pom. 有趣的是,maven:准备步骤确实在正确的pom上执行。

What I tried so far 到目前为止我尝试了什么

  • Not using jenkins, and invoking the mvm command directly from the shell. 不使用jenkins,直接从shell调用mvm命令。 This gives me the same outcome. 这给了我相同的结果。 So I assume that jenkins is not the issue. 所以我认为詹金斯不是问题。

  • Changing the path for the pom with the -Darguments="-f sword-packaging-wbf/pom.xml" and with -Darguments="-DpomFileName=sword-packaging-wbf/pom.xml" 使用-Darguments="-f sword-packaging-wbf/pom.xml"-Darguments="-DpomFileName=sword-packaging-wbf/pom.xml"更改pom的路径

    Both methods do not change anything in the outcome. 两种方法都不会改变结果中的任何内容。 And looking at the output I see that the -f <path> is ignored in the generated commands where as the -DpomFileName is visible but does not change anything in the outcome. 在查看输出时,我看到生成的命令中忽略了-f <path> ,其中-DpomFileName可见,但不会更改结果中的任何内容。

So this means your organization is simply wrong. 所以这意味着你的组织完全错了。 Put your parent into a separate maven module (also separate git repos) release it. 将您的父母放入一个单独的maven模块(也是单独的git repos)释放它。 In your child modules just use the parent and make your childs separate maven modules as well as git repos and release them separately. 在您的子模块中,只需使用父模块,让您的孩子分开maven模块以及git repos并单独释放它们。 That's it. 而已。 Otherwise you start fighting with Maven and you will loose the combat. 否则你开始与Maven战斗,你将失去战斗。

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

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