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.

machine bitbucket.org  
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'  

Maven JGitFlow - Working tree has uncommitted changes

When I was trying to start a new release using Maven jgitflow plugin, it always complained about Working tree has uncommitted changes. I checked Git repository using git status -s and it seemed that all changes had been committed. I even tried to use git clean -f -d to clean all untracked files, even though I'm pretty sure that I already configured jgitflow to allow untracked files using <allowUntracked>true</allowUntracked>. But still no luck.

After searching for a while, I found out jgitflow actually has a gitflow log file. The log file is .git\jgitflow.log in your project's directory. After checking the log file, I found out it's caused by case insensitive path on Windows for Git. The momentjs library I'm using has changed the name of readme file from readme.md to README.md. But this change is not detected after I used Bower to update the library due to case insensitive path.

After knowing that, the fix is quite easy. Just use git mv to rename the file, git mv -f moment/readme.md moment/README.md. Then commit the change and jgitflow starts working again.

The key takeaway point here is to remember to check .git\jgitflow.log log file if you have jgitflow issues.