Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

David Paquin September 9, 2014

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

1 vote
John Snead September 9, 2014

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.

 

David Paquin September 10, 2014

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...

0 votes
David Paquin September 9, 2014

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?

0 votes
Adrian Moerchen
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.
September 9, 2014

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".

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events