Automate the version assignment with Maven release:prepare in Bamboo


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?



3 answers


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.



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}" ${}\Build\

(modify for whatever string you have in your pom file, in my example above I'm matching what is in the 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.

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

Suggest an answer

Log in or Sign up to answer
Community showcase

Scrum Roles Explained: the Do's and the Don'ts

Hello Community,  Today we are going to talk about the three Scrum Roles. There is the Development Team, the Scrum Master and the Product Owner. In my opinion these three are all really impo...

106 views 1 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you