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

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

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

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 Join to answer
Community showcase
Renan Battaglin
Published May 18, 2017 in Bamboo

FAQ: How to Upgrade Bamboo Server

Bamboo 5.9 will no longer be supported after June 12, 2017. What does this mean? As part of our End of Life policy, Atlassian supports major versions for two years after the first major iteratio...

1,096 views 0 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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot