Monday, October 1, 2012

Fun with git remote branches

I am currently using the build-per-branch-"Plugin" to integrate my git-flow-enabled projects with Jenkins continuous integration.

After creating and removing a few feature/hotfix/release branches I noted that some branches that should have been deleted kept returning in my list of Jenkins jobs.

So, nobody likes zombie jobs, right?

I started digging into the build-per-branch plugin. It uses "git ls-remote --heads " to retrieve the  list of remote branches. 
And behold: my branches that "git branch -r" would no longer show were still listed there!

I did delete the branches using "git branch -r -d " and it told me that the remote branch was removed.

There is the other way for deleting remote branches: Pushing an empty repository to a remote branch with "git push origin :" (I confess that I often have used "git branch -r -d" because I could remember it more easily). 

But as it turns out the only surefire way to get rid of a remote repository seems to be to use "git push origin :", becuase after this "git ls-remote" no longer lists the reference for the branch's head.

Update: I asked about this behavior ont the git mailing list:

Hi,

I came across an issue with deleting remote branches: When deleting a
branch using "git branch ­r ­d " the branch is deleted and no
longer shown by "git branch ­r".

"git ls-remote --heads" on the other hand still lists the ref for the last
branch commit.

If I delete the branch using "git push origin :" the branch is
removed completely (i.e. git ls-remote  no longer returns a ref).

Is this a bug or is this behavior intentional? (I am currently using git
1.7.12).
Here is the response I got from the git mailing list:

All of the above are expected and working as designed.  Remote
tracking branches are local _copies_ of what you have over there at
the remote repository. The latter is the authoritative version, and
you asked "ls-remote" to go over the network to view them.

If you are trying to remove the branches you show to others and
yourself who are observing that remote repository from your local
workstation, you can first "git push origin :" to remove it
in the remote repository. You can run your next fetch with "--prune"
to get rid of remotes/origin/, I think.
I think it clarifies the behavior. That thing that "git branch -r -d" deletes is only the local reference of the remote brach (the rempote tracking branch), i.e. the git branch command works fully locally.

Only git push will really change *anything* on a remote repository.

Tuesday, August 21, 2012

The perils of gradle wrapper and CI

If you are building yours software with Gradle, using gradle-wrapper is a great thing to ensure that your build is able to run out of the box after checking out just by running "gradlew" in your project directory.

Just today I got a nice message from Hans Dockter (gradleware Germany), telling me that there have been a lot of downloads of gradle-1.0 (about 2100) in the course of one or two months, which caused some notable trafic on gradle.org.

 2100 downloads check in at about 64 GB of data.

So, what was the cause? As we don't have an infinite number of monkeys using gradle here, the primary suspect is jenkins.
A good number of jobs (about 20) use Gradle for building, and each job is configured to use Gradle wrapper, because it is convenient and ensures the build runs exactly with the right Gradle version.

So it seems like every job was happily downloading Gradle over and over again, which puts some load on gradle.org (bad)  and slows down the build (even worse).

The solution is simple: Just installGradle centrally on your Jenkins and configure the Jenkins jobs to use the centrally provided Gradle instance. I am dong this for my jobs right now and I expect them to behave better afterwards.

I am sure that gradle.org and the speed of your build jobs will thank you for it.

Tuesday, October 19, 2010

Encoding your passwords in Maven

If you dislike storing your passwords in clear just like me then Maven 2.1.x or 3.x can help you out.

At the Maven site the documentation is somwhat hidden, so I'll just describe the process in short and put up a link to the relevant documentation.