Paul Gregoire Paul Gregoire - 14 days ago 4
Git Question

How to get branch into manifest

Using the

buildnumber
maven plugin, I would like to get the branch stored in my jar manifest. I have tried it two different ways, shown below.

Here is the output from my build (relevant section only)

[INFO] --- buildnumber-maven-plugin:1.4:create (default) @ myproject ---
[INFO] ShortRevision tag detected. The value is '7'.
[INFO] Executing: /bin/sh -c cd '/workspace/myproject' && 'git' 'rev-parse' '--verify' '--short=7' 'HEAD'
[INFO] Working directory: /workspace/myproject
[INFO] Storing buildNumber: ed5ea17 at timestamp: 1479511476753
[INFO] Storing buildScmBranch: bug/abuginthesystem


Here the plugin section from attempt 1 (SCMBranch key from plugin website):

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<shortRevisionLength>7</shortRevisionLength>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifestEntries>
<Build-OS>${os.name} ${os.version}</Build-OS>
<Build-Java>Java ${java.version}</Build-Java>
<Build-Number>${buildNumber}</Build-Number>
<Build-Branch>${SCMBranch}</Build-Branch>
</manifestEntries>
</archive>
</configuration>
</plugin>


Attempt 2 using the build out:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<shortRevisionLength>7</shortRevisionLength>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifestEntries>
<Build-OS>${os.name} ${os.version}</Build-OS>
<Build-Java>Java ${java.version}</Build-Java>
<Build-Number>${buildNumber}</Build-Number>
<Build-Branch>${buildScmBranch}</Build-Branch>
</manifestEntries>
</archive>
</configuration>
</plugin>


Manifest output from both is:

Manifest-Version: 1.0
Build-Java: Java 1.7.0_79
Build-Number: ed5ea17
Build-OS: Linux 4.4.0-47-generic
Built-By: mondain
Build-Jdk: 1.7.0_79
Build-Branch:
Created-By: Apache Maven 3.3.9
Archiver-Version: Plexus Archiver

Answer

If you want to use the following in your manifestEntries:

<Build-Branch>${buildScmBranch}</Build-Branch>

Then you should use the following in the configuration for the buildnumber-maven-plugin:

<plugin>
    <artifactId>buildnumber-maven-plugin</artifactId>
  ...
    <configuration>
        <scmBranchPropertyName>buildScmBranch</scmBranchPropertyName>
      ...
Comments