3

I am trying to figure out a way to create Build Tags on items in Git

My thoughts were to have Jenkins do the tagging as seen by the article below.

According to this article: http://www.nailedtothex.org/roller/kyle/entry/configuring-automatic-push-by-successfully

My understanding is that the version numbers are to be generated in the following way:

(Major version).(Minor version).(Revision number).(Build number)

1.2.3 (11BCF) <- Build number, should correspond with a revision in source control
^ ^ ^
| | |
| | +--- Minor bugs, spelling mistakes, etc.
| +----- Minor features, major bug fixes, etc.
+------- Major version, UX changes, file format changes, etc.

according to this message: https://softwareengineering.stackexchange.com/questions/3199/what-version-naming-convention-do-you-use

I have 4 levels for the project that PRODUCTION, TEST, CONSOLIDATION, DEVELOPMENT.

The releases look like

 PRODUCTION    (generate deploy build only if major/minor/revision number changes)
     ^         (send to STABLE repository)
     |
   TEST        (generate deploy build only if major/minor/revision number changes)
     ^
     |
CONSOLIDATION  (generate all of the time)
     ^
     |
DEVELOPMENT    (generate all of the time)

How can I fix the $BUILD_NUMBER so that it ($BUILD_NUMBER) is generated according to: (Major version).(Minor version).(Revision number).(Build number)

What can I pass to a Jenkins Job (during configuration) so that it recognizes changes in the (Major version).(Minor version).(Revision number)

Is there a better way to make this happen?

TIA

Casey Harrils
  • 2,793
  • 12
  • 52
  • 93
  • BUILD_NUMBER is part of Jenkins build process, and got generated automatically whenever the job got kicked off, I think you were sort of referring to the Jenkins pipeline to more control flow thing, like SCM-tagging, or version number change. – chenrui Dec 31 '17 at 04:38
  • not sure about which language do you use, but each build tool can facilitate on the version number management flow as well. – chenrui Dec 31 '17 at 04:39

1 Answers1

2

You cannot change BUILD_NUMBER, managed sequentially by Jenkins.

But you can make sure one of your Jenkins job build step generates a tag (following the semver convention), and then recompile your project one last time, with a property file generated with those version information.

See "Applying the existing tag on a new commit in Git".

This uses the ktoso/maven-git-commit-id-plugin maven plugin.
It allows for your project to refer at runtime to this generated property (key/value) file, where you can find X.Y.Z but also the Git SHA1.
That plugin will run git describe for you:

The format of a describe result is defined as:

v1.0-2-g2414721-DEV
 ^   ^  ^       ^
 |   |  |       \-- if a dirtyMarker was given, it will appear here if the repository is in "dirty" state
 |   |  \---------- the "g" prefixed commit id. The prefix is compatible with what git-describe would return - weird, but true.
 |   \------------- the number of commits away from the found tag. So "2414721" is 2 commits ahead of "v1.0", in this example.
 \----------------- the "nearest" tag, to the mentioned commit.
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • thanks for the response. I will use this when working with Java and Maven :-) As of now, I am working with Python and DJango. Code from Python / Django has been pushed into the Git repository. The Python / DJango code is checked out - under Jenkins - to create a Docker image. I was looking to generate a release version so that it could be 1) applied to a Docker tag for the Docker Image and 2) apply the same tag to the Git repository (Python/DJango) that was involved when the Docker image was made. Will the Maven plug-in work in this case as well? Again, thanks for the response! – Casey Harrils Jan 01 '18 at 23:00
  • @CaseyHarrils Sure it would, in that git describe can be used to generate a tag used by both Docker and Git. If you don't use maven, you can still call git describe for that purpose. – VonC Jan 01 '18 at 23:02
  • thanks for the information again. Will try it out and update with the results TIA – Casey Harrils Jan 01 '18 at 23:30