Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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):

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.

For our release we use the jenkins as build server with the Jenkins Maven Release Plug-in to start the release build.

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.

Due to the way how git is working I can only clone the top level of my structure. 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.

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). 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.)

This is the value of the Release goals and options field in the jenkins JobB configuration:

-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.

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). 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.

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. 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:

[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. Interestingly the maven:prepare step does execute on the correct pom.

What I tried so far

  • Not using jenkins, and invoking the mvm command directly from the shell. 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"

    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.

like image 862
Chris Avatar asked Feb 21 '23 16:02

Chris


1 Answers

So this means your organization is simply wrong. Put your parent into a separate maven module (also separate git repos) release it. In your child modules just use the parent and make your childs separate maven modules as well as git repos and release them separately. That's it. Otherwise you start fighting with Maven and you will loose the combat.

like image 128
khmarbaise Avatar answered Apr 26 '23 19:04

khmarbaise