Automate the version assignment with Maven release:prepare in Bamboo

Wahid Atif January 5, 2014

Hi,

I am working on automating the maven release process in a Bamboo plan.

In a Maven task I have the following release:prepare command using both global and plan variables:

release:prepare --batch-mode -Dusername=${bamboo.custom.svn.username} -Dpassword=${bamboo.scmPassword} -DdevelopmentVersion=${bamboo.snapshotVersion} -DreleaseVersion=${bamboo.releaseVersion}

Both variables ${bamboo.snapshotVersion} and ${bamboo.releaseVersion} are defined at plan level.

Actually, the intent behind setting the maven parmateres "developmentVersion" and "releaseVersion" is to pass a customized version number. But by this way, the users must each time run a customized build and passes the correct parameter values.

Now I need to configure my Bamboo plan, to achieve both use cases in one plan:

1- Pressing "run build" without passing the values for the version variables just leaves the maven release plugin to determine the next development version.

2- Using "run customized build" and overriding both variables will produce the given version numbers for release and snapshot.

While searching I found these 2 interesting plugins:

The first (beta) plugin "bamboo-maven-version-update-plugin" offers the possibility to auto-increment the version values in both variables, in case they might be forgotten. But it can't sync the snapshotVersion variable with the POM’s version to make sure they’re the same value.

While the second one "Maven POM Value Extractor" can keep the plan variable ${bamboo.snapshotVersion} in sync with the POM element "<version>" before performing release:prepare. But the value for ${bamboo.releaseVersion} in turn will still have to be set manually.

I thought I could define 2 tasks by using both plugins before performing the release:prepare task to:

1. Keep the plan variable ${bamboo.snapshotVersion} in sync with <version> element in POM.

2. Auto-increment the ${bamboo.snapshotVersion} variable if not given explicitly by the user.

But I didn't find a way to "auto determine" the ${bamboo.releaseVersion} value if not given.

Is it even possible to achieve this?

Regards,

Wahid

3 answers

0 votes
Robert Hendy October 15, 2015

I have the exact same use case as described here, anyone have any further ideas??

0 votes
Gretchen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 18, 2014

I retrieve the major minor revision number from a .properties file in order to validate that it is correct. I use a small regex script to do the parsing. Something like:

FINDSTR /X /I /C:"version=R${bamboo.current.version}" ${bamboo.build.working.directory}\Build\release.properties

(modify for whatever string you have in your pom file, in my example above I'm matching what is in the release.properties file against a user entered variable ${bamboo.current.version} to validate that the developers remembered to update the version number which is done manually in the source. You would not be matching but parsing for some pattern like: version= \d+.\d+.\d+ and isolating the part you wanted for your variable then assigning that to whatever gets written to the txt file.)

Just kicking it around, I'd write the results of that query to a txt file, inject it using the injection variable. You could add some math to the number by breaking it up into it's parts, incrementing what needed incrementing and appending the parts back together again before writing it.

No question, it's a clumsy implementation but it can be done. There's probably some really smart guy out there who could give you a much more elegant solution, if he's paying attention. I think the hardest thing about using bamboo is figuring out what bamboo can do and what you have to do yourself so that you can pass it to bamboo.

0 votes
Gary Kennedy February 3, 2014

+1

Similar situtation, where I would like to increment plan variables. Deployment plans are great, but when you need the release version (and the next release/development version) for the build plan itself they are useless.

Cheers,

Gary

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events