Thursday, September 26, 2013

Jenkins + git revision in all build names

Martin Podval
Jenkins by default assigns version of a build using local counter within each type of a build. An example is better.


When you look at this overview, you definitely do not know which code revision was used in Compile build and which in Integration Tests. I've followed nice article regarding real CI pipeline using jenkins. It uses Build Name Setter Plugin. Unfortunately this article uses SVN revision number.

So I said I'll just use git revision as git is my source control. But it's not so easy as how it could seem for first look.

My Jenkins setup comprised of first compile build step which clones git server and performs an compilation. Second build steps clones the repository from first step and executes integration tests. The problem here is that the second step does not know which git revision compile step cloned.

Here is list of steps how to do that.

1. You obviously need Git Plugin, Build Name Setter Plugin and Parameterized Trigger Plugin
2. Compile build requires following Post-Build action using Parameterized Trigger Plugin


This will introduce new environment property called GIT_REVISION with value equals to current cloned git revision.

3. Integration Test build uses Build Name Setter Plugin's option along with following code:
PL#${ENV,var="GIT_REVISION"}-${BUILD_NUMBER}



And that's all.


About me

Powered by Blogger.