Accessing the VCS changes since the last build in a Task script

I have a Bamboo build that uses two git repositories -- one for the source code, one for some ancillary information about the project. I have a scheduled task that runs once a day, which builds the source, runs some tests, then automatically commits some metadata to the ancillary repository.

I stumbled across,+plan+or+build-specific+variables and it got me wondering... is it possible to get the list of commits / changelog that a bamboo build ran with? I'd love to get this list in to my commits to my ancillary repository.

5 answers

1 accepted

Hm... I think you should be able to get the SHA of the current/previous build commit. I'd expect you're interested in:


variables. I'm not sure why do you need the current build number, but if you need: bamboo.buildNumber - that's the variable I'd use.

Now, the tricky part would be to glue that up in the external script (external script is in my opinion a first option to check, as I agree it will be more viable than writing up java plugin, or seeking for one). The general gist is that you should add a Script Task with inline script looking something alike:

git log ${bamboo.repository.previous.revision.number}..${bamboo.repository.revision.number}

...and do something with the output. Trick is that I'm not 100% sure these variables are working for Git repositories. I reckon they work definitely for SVN repos, but I'm not sure if the are working nicely with Git - I can check that after Easter. The second trick is that as you have two repos definined in your plan you might have to use prefixing syntax like


to tell Bamboo which exactly repository you're interested in - but I can't check ATM what is the syntax (I don't remember :) ) and whether it is necessary at all.

Am I helpful? :)

Hi Chris,

Do you consider writing up a Bamboo Task Plugin? or do you want to base on only 'external' Script Tasks, without touching Bamboo Java API?

0 vote

Ideally I'd like to get away without needing to write my own plugin -- if there's one available out there aready that does the trick that'd be dandy. But if it comes to writing my own, I wouldn't be averse to plumbing the Java API for the info I wanted.

I suppose the alternative is that I could indeed write an external script to interrogate the git repository, though to make it viable I'd need to be able to get:

* The SHA of the commit for the current build,

* The current build number, and

* The SHA of the commit for the previous build.

Then I could just use Git commands in the script to get the git log I'm after.

0 vote

Thanks Piotr, that's definitely helpful. I'd accept it as the answer, except it's a comment :P

Hi, I've found an innocently looking button titled "Convert comment to answer" here. Apparently it does exactly what it is named. Though I can't rollback that operation.

<pedant mode>Anyway, feel free to accept the answer now. :)</pedant mode>Or ignore it. I don't mind - happy to hear it was helpful.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
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,563 views 0 6
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