2 posts

JGit Flow Maven plugin integration with Bamboo

JGit Flow is a good plugin to apply git-flow practice with Maven projects. Since it's a pure Java implementation, it's very easy to integrate with most CI servers.

However, if you are using Atlassian Bamboo, there are some workarounds for particular issues.

Git repository url

Bamboo use a fake Git repository after checkout. The repository's url is something like file:///nothing. So JGit Flow cannot perform actual Git operations on this repository. You can:

1) Set repository url in plugin configuration

    <defaultOriginUrl>[repository url]</defaultOriginUrl>

2) Use Git command to update repository url

${bamboo.capability.system.git.executable} remote set-url origin ${bamboo.repository.git.repositoryUrl}

Git repository authentication

You can use -Dusername and -Dpassword in JGit Flow plugin to set the repository's username and password. To execute Bamboo shell script with Git commands, a .netrc file with authentication details needs to be created. This can be done via agent start script or using echo in inline script.

login <username>  
password <password>  

Clean old release branches

After finishing a release using release-finish, the remote release branch is deleted by default. But the branch may still exist in local. These old release branches should be removed, otherwise next release-start goal will fail.

${bamboo.capability.system.git.executable} fetch --prune --verbose

${bamboo.capability.system.git.executable} branch -vv | awk '/: gone]/{print $1}' | xargs ${bamboo.capability.system.git.executable} branch -d 2> /dev/null

echo 'stale branches deleted'  

Atlassian Elastic Bamboo - Update Maven Settings

When using Atlassian Elastic Bamboo to build Maven project, it's a common task to update Maven settings.xml to add private repository information, e.g. credentials to access company's private repository.

Below are two approaches I find to update Maven settings.

Add settings.xml to code repository

The first approach you can take is to add the settings.xml to your code repository, then specify the path to settings.xml file using -s option of mvn command.

Suppose the settings.xml is in the root directory of your project, use mvn -s settings.xml clean deploy as the command line to invoke Maven.

Update settings.xml in Bamboo image

If an Amazon EBS volume is added to the Bamboo agent, you can directly change the settings.xml file. Atlassian has a guide on how to do this. Below is a much simpler guide on how to do it.

  1. Start the Bamboo agent
  2. Edit the file /mnt/bamboo-ebs/maven/.m2/settings.xml. Not the one /home/bamboo/.m2/settings.xml. /home/bamboo/.m2/settings.xml is copied from /mnt/bamboo-ebs/maven/.m2/settings.xml after agent started.
  3. Find the EBS volume used by the running agent.
  4. Create a snapshot from the EBS volume.
  5. Update Bamboo elastic image configurations to attach the new snapshot.
  6. Done!