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

How to tag plan's branch with build number?

Video Guy February 2, 2016

We have a Bamboo plan that builds whenever changes get pushed to our release branch. Lets call this branch release/steamboat. I like to tag this branch after a successful build. Something like steamboat_118 for build 118.

I don't see any tasks in Bamboo task panel to facilitate this.

 

How do I do this?

Thanks for your help!

 

2 answers

0 votes
Video Guy February 22, 2016

I appreciate detailed response! For some reason, the images you attached seem broken. I don't see any of them. I am looking at it using Firefox.

Tim Crall
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.
February 22, 2016

Sorry about that; I copied and pasted from another (internal) wiki, the images appear to me but they're probably inserted as links to my server which is behind a firewall.

I will work on uploading them.

Video Guy February 23, 2016

Thanks Tim!

Tim Crall
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.
February 23, 2016
0 votes
Tim Crall
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.
February 2, 2016

If you have an application link established, Stash should automatically display a build results icon next to commits and branches that have been built.

If you do want to have Bamboo actually apply a tag to Git, you can do it, but it's not as easy as you might think.  Below is a guide I've written on it.

---

Bamboo does not have a way to automatically tag a commit in Git, but it is possible to do this with a little scripting.

Setup SSH Certificates

One problem is that the Bamboo build machines (agents) do not have the same SSH certificates set up as does the Bamboo server itself.  Therefore in order to authenticate from the Bamboo agent, you will have to create a pair of SSH keys and add them to your repository.  

Clone your repository onto a linux machine or a Macintosh and follow the steps shown below.

% git clone ssh://git@stash.mycompany.com/project/helloworld.git

% cd helloworld

% mkdir ssh_keys

% cd ssh_keys

% ssh-keygen -t rsa -b 4096 -C "bamboo@cdk.com"

Enter file in which to save the key (/Users/crallt/.ssh/id_rsa): ./id_rsa (do not accept the default value or it will place your files in ~/.ssh and overwrite any keys already there!)

Enter passphrase (empty for no passphrase): 

Enter same passphrase again: 

Your identification has been saved in ./id_rsa.

Your public key has been saved in ./id_rsa.pub.

 

Now create a file named ssh_proxy.sh within your ssh_keys directory

% cd ssh_keys

% vi ssh_proxy.sh (or editor of your choice)

paste in the following text and save the file.

#!/bin/bash
THISDIR="`dirname "$0"`"
set -vx
ssh -o StrictHostKeyChecking=no -i $THISDIR/id_rsa $1 $2 $3 $4

This creates a shell script that will launch the SSH command using the provided public key.

Add this new directory to your repository.

% git add .

% git commit -m "Added SSH Keys"

% git push

Now cat the contents of the id_rsa.pub file, select, and copy it to your clipboard with CNTRL-C or CMD-C as appropriate.

Go to the web interface for your Project in Stash. Click on Settings (note: you must have Administrator access on the repo to do this - if you do not, please consult a Project Administrator). Select Access Keys. Click "Add key".

Select Read/Write and paste in the contents of the id_rsa.pub file which you previously copied onto your clipboard. Click "Add key"

Script the Build Plan

Now that your SSH keys have been set up, it's time to add a script to your Bamboo build plan. Browse to your Build Plan within Bamboo and select Actions->Configure Plan. Select the stage where you want to add the tagging and click Add task. Scroll down and click on "Script"

Our script has to do three basic tasks. First, it has to configure itself to use our provided SSH keys. Then it has to apply the desired tag on the local clone of the git repository. Finally, it has to push the change back to Stash. This is complicated slightly by the fact that Bamboo does a weird kind of cloning that not retain the "origin" information. So we have to create a new remote and assign it the correct URL to push back to.

For a Linux Build Agent:

Click Add task and select "Script"

For the script body, enter something like this:

For a Windows Build Agent:

Click Add task and select "PowerShell Task"

For the script body, add something like this:

Conclusion

You will want to change line 12 ("git tag") in either script with something that puts the desired tag onto the commit - probably pulling it out an environmental variable that you've defined for that purpose.

The above script also assumes that it is the master branch that you are wanting to tag - modify accordingly otherwise.

Once you've done this, you should be able to run your build plan and tag the latest commit.

 

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events