Best way to write build number into project and commit back to git/Stash?

I'm new to Bamboo, and have created a few projects in it so far. All of them are linked to repositories in Stash. Each time a build occurs I'd like to increment a build number (currently I'm using buildnumber in ant), write to the project I'm building (set its build number), and then commit that new build number back to git/Stash. I have the first 2 parts down, but is there a way to commit back to git?

 

Like I say, I'm still quite green when it comes to Bamboo, so perhaps I'm going about this wrong... How do others handle build numbers in Bamboo?

3 answers

This widget could not be displayed.

Hi David and Adrian,

One reason to write back to the repo at the end of a build is to map commits in the repo to builds. We do this by creating a tag containing the build number. Developers can then tell at a glance which commits were in which build. I'm not totally satisfied with the way I have implemented it at the moment, but I have an inline script task as the last task, which contains:

cd ${bamboo.build.working.directory}\${bamboo.projectkey}\${bamboo.repo}
"C:\Program Files (x86)\Git\bin\git.exe" tag "${bamboo.buildKey}_${bamboo.buildNumber}"
"C:\Program Files (x86)\Git\bin\git.exe" push --tags http://buildadmin:${bamboo.buildadmin.password}@10.10.60.105:7990/scm/${bamboo.projectkey}/${bamboo.repo}.git

(some of the variables here are ones we define for every plan - projectkey, repo, and it's obviously our URL and username. BTW I couldn't get SSH to work here and various Atlassian &/or StackOverflow answers said to use http. You hide the password using the shared credentials facility)

By the way, if you were to update and push a file back, you prevent a build being triggered (recursively!!) by setting an exclusion on that file in the build plan repo definition.

 

Thanks for the insight - I'll check that out! I also just realized that there is the whole Deployment portion of Bamboo which I haven't started using yet. It seems to have a lot of features in it for adding build numbers to the deployed files, so perhaps that is another way I could go about it...

This widget could not be displayed.

Hello David, Why would someone write back the build number into the repository? This way you would alter the repository with unnecessary information. (By the way, how would you prevent this to trigger a new build?) Typically Bamboo is used to create final artifacts, which are more or less ready to ship, and though you will typically append the final artifact with the build number somehow. For instance write it just to a file called "version.txt".

This widget could not be displayed.

So we can get the current version during development, for example, to write an upgrade script targeting versions newer than 2.1.15 (where the 15 is the build number from Bamboo). Or to write the code to show the current application version number somewhere. Should I put a blank version.txt file on the development machine, or keep updating it with the latest build number from bamboo perhaps?

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Friday in Bitbucket

What is your #1 piece of advice to new users getting started using Bitbucket?

Hello Community! My name is Claire Maynard, and I’m a Product Marketing Manager on the Bitbucket team. I’m interested in hearing what advice or tips you have for new users getting started on ...

136 views 5 2
Join discussion

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