2

We have a requirement to support human defined versions (not auto generated) for patch releases. I'm trying to figure out a way to do this in Jenkins.

We have:

  • BitBucket, Jenkins, Nexus/JFrog (either).
  • trunk based development with release branches.
    • development happens in master
    • when release is GA, create a new release/vN branch from master
    • while release is under support, bugfixes go into release/vN, and are released as patches every week/month.
    • commits to release/vN get auto merged into master release/vN+1, release/vN+2, ...
  • versions as v<major>.<patch>

Want the ability to:

  • plan for an upcoming patch by naming it:
    • say current release in prod is v2.1
    • we want to communicate to stakeholders that v2.2 is coming up next Friday.
  • build and create an artifact artifact-v2.2.tar (/jar/war/..) and push it to a repository like Nexus/JFrog.
  • include a text file build-version inside the artifact that contains the version v2.2.
    • this is so the code "knows" which release is it, e.g. to include in logs/metrics etc.

Problem:

  • if we put build-version under version control, it'll break auto-merges for bugfixes etc.
  • can not auto generate the version during build because it's supposed to be human defined.

My solution is:

  • change to be released is merged into say release/v2 branch as commit with sha-22
  • tag the commit with v2.2 (= git tag -a 'v2.2' sha-22)
  • goto Jenkins and trigger a parameterized job with param (say CHECKOUT_REF_SPEC) value as v2.2
  • Pipeline will checkout the CHECKOUT_REF_SPEC (= git checkout v2.2)
  • compile: (= mvn clean compile)
  • create a new file with tag value (= echo $CHECKOUT_REF_SPEC > target/build-version)
  • package: pass CHECKOUT_REF_SPEC to maven (= mvn -P"artifact.version=v2.2" package) to produce artifact-v2.2.tar
  • push to artifactory.

(I have half the Jenkinsfile coded, and can post it here if it helps)


Question: Is there a better/more-elegant way of doing this?

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.