Reputation: 881
my jars are installed remotely by ssh, it is important that I know which version was installed. This is not accomplished via my current use of version numbers in the pom.xml since this number is manually updated. what I want to be able to do and cant find a decent plugin or one clear enought to tell me. Jenkins should build rev a build number in the pom file (e.g. 1.0.3. or 1.0.3- or 1.0.3_ or simply an additional attribute called build number) It would be good to have this build number as part of the jar name so that it is easily distinguished etc. etc.) Any ideas?
Upvotes: 2
Views: 8383
Reputation: 1
Although, Maven was not designed with this feature as one should not consider every build commited by VCS, because of stability of the build to release. But there is a work around with use of plugins. I will not suggest to version builds with build number but to use this practice with releases.
Addition in POM file:
Step 1: configure SCM as follows
'<scm>
<connection>scm:git/svn:repositary location</connection>
<url>similar</url>
</scm>
--
--
<build>
--
--
<plugins>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.9.2</version>
<configuration>
<connectionType>connection</connectionType>
</configuration>
</plugin>'
**Step 2: Use BuildNumber Plugin **
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
<configuration>
<format>{0,date,yyyy-MM-dd_HH-MM}</format>
<items>
<item>timestamp</item>
</items>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Step 3:
<finalName>webapp-demo-${buildNumber}</finalName>
${buildNumber} can be timestamp or changeset/revision. It totally depends on your need. Tutorial
Upvotes: 0
Reputation: 97447
Starting with Maven 3.2.1 you can define properties in your version things like this: ${revision}
, ${changelist}
, and ${sha1}
.
<groupId>com.soebes.examples.j2ee</groupId>
<artifactId>parent</artifactId>
<version>1.0.4-${revision}-SNAPSHOT</version>
This is one solution.
You can also put all the needed information into a MANIFEST.MF file so you are always able to exactly say which version is installed. There you can either svn revision number or git sha1 and supplemental things like the build number of CI solution.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<configuration>
<archive>
<addMavenDescriptor>true</addMavenDescriptor>
<index>true</index>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
<manifestEntries>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<revision>${svn.revision}</revision>
<build-number>${BUILD_NUMBER}</build-number>
<build-id>${BUILD_ID}</build-id>
<build-time>${maven.build.timestamp}</build-time>
</manifestEntries>
</archive>
</configuration>
</plugin>
Upvotes: 1
Reputation: 1796
This post describes a way to use the Jenkins internal build number in a Maven project. But there are some adaptations necessary to match your requirements.
<properties>
<build.number></build.number>
</properties>
The property should have an empty value default value. If build number is not specified (as Java system property), the name of the jar will be as normally ${artifactId}-${version}.jar e.g. myartifact-0.0.1-SNAPSHOT.jar
<build>
<finalName>${artifactId}-${version}${build.number}</finalName>
</build>
The final name will now include the build number as suffix. For example: myartifact-0.0.1-SNAPSHOT-153.jar (Please note, that the hyphen before the build number must be part of the system property - see next step)
mvn clean install -Dbuild.number=-${BUILD_NUMBER}
Please note, that the hyphen before the build number!
Upvotes: 1