Question

I am using the "Merge before build" option of the git plugin to build a maven job. I have tried using ${GIT_BRANCH} and ${GIT_COMMIT} in my maven pom to write the commit information into my built artifacts but these variable are set to the branch being merged and its commit SHA-1.

Is there a way that I can find the SHA-1 of merged code and pass it into maven?

Was it helpful?

Solution

The Mojo's Buildnumber Maven Plugin can fetch this information for you.

The project site has not been fully updated to reflect the fact that it works with GIT.

<build>
  <plugins>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>buildnumber-maven-plugin</artifactId>
      <version>1.1</version>
      <executions>
        <execution>
          <phase>validate</phase>
          <goals>
            <goal>create</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <doCheck>true</doCheck>
        <doUpdate>true</doUpdate>
      </configuration>
    </plugin>
  </plugins>
</build>

That will set the ${buildNumber} property to the full GIT hash of your workspace.

It also will have the side-effect of ensuring that the build is the same on either a developers machine or the CI build server.

OTHER TIPS

You can also try the maven git commit id plugin. It will provide you with a lot of information from Git, it supports fancy formatting and many different use cases.

Direct link to the documentation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top