How do i successfully use the Maven release plug-in with GitHub (or GitHub enterprise) when using a CI tool like Hudson/Jenkins

Problems encountered are

  • Maven does not commit if the pom.xml is in a sub folder rather than top level. Due to this subsequent builds fail with tag name already exists.
  • In spite of setting up public key authentication between the source server that runs the CI job, git push fails with one of the following errors
    • public key authentication failed
    • unknown service git
1

There are 1 best solutions below

0
On

There are multiple things that need to be correct for this to work.

  1. For the sub-folder commit of pom.xml to work, the bug is resolved in Maven release plug-in 2.5.1. Get the latest with the dependencies. The below section shows the pom.xml

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-release-plugin</artifactId>
        <version>2.5.1</version>
    
        <dependencies>
            <dependency>
                <groupId>org.apache.maven.scm</groupId>
                <artifactId>maven-scm-provider-gitexe</artifactId>
                <version>1.9.2</version>
            </dependency>
        </dependencies>
    
        <configuration>
            <checkModificationExcludes>
                <checkModificationExclude>pom.xml</checkModificationExclude>
            </checkModificationExcludes>
        </configuration>
    </plugin>
    
  2. Correctly configure the SCM section in pom.xml. For public key authentication to work, use SSH protocol. For https protocol, user/password will be needed, this answer does not cover that. It should be possible by providing user/pwd in the Maven settings.xml in the servers section.

    <scm>
        <developerConnection>scm:git:ssh://github.com/org/repo.git</developerConnection>
        <url>https://github.com/org/repo</url>
        <tag>HEAD</tag>
    </scm>
    
  3. Create a user called git in your source server. If you run as any other user, the developerConnection url will need to have [email protected] in stead of github.com. Maven will try to put a git:****** in the git push command and it fails as service unknown. If you use any other user to SSH into github, it will reject with public key authentication failed.

  4. Using the git as user, generate SSH keys and configure following the simple steps below

    https://help.github.com/articles/generating-ssh-keys/

  5. Edit your Hudson/Jenkins job as below

    • Under the source code management section, provide the URL of the git repo. You might need to put git as protocol as some CI installs do not support https.
    • Mention your branch in branches to build (e.g. development)
    • Click advanced and put the same branch name in the section "Checkout/merge to local branch (optional)"

Run your job with maven goals clean compile release:prepare and release:perform. It should work.