Jenkins + git revision in all build names

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.

Git on Windows: MSysGit

I have started to use Git today. I read a lot of discussions that there is no good tool for Windows platform. After forethought I have decided to used TortoiseGit. I also feared of difficult work related with Git as a lot of articles mentioned many instructions. As I already said, I have decided to use TortoiseGit, because I’m used to work with TortoiseSvn, but for start, MSysGit is enought. So this article is about MSysGit, next will be about TortoiseGit.

How to start with MSysgit on local machine?

  1. Download and install Git for Windows
  2. Create source code directory for your git app
  3. Right click the directory at your favorite file browser. Menu should contain item “Git init here”. It initializes chosen directory to be git-abled 🙂

It was your first usage of Git.

Commit data to local Git repository

Now, you can add any file, your first source code, to created directory. If you are prepared to commit any changes to your local git repository, follow next instructions.

  1. Right-click the directory.
  2. Choose “Git Add All file now”. The command adds all files to git control. No commit so far, lets say that it’s similar to subversion’s “Add file”
  3. Right-click again, now choose “Git gui” item to start graphical GIT client.
  4. You should see your changes prepared to commit to local git storage. You can write your comment and commit changes.

Push data to remote server – github.com

As I said, your commit so far affected only local repository. If you decided to share (or backup) your sources to real server, thats another story 🙂

To do that, I have assigned to free-for-public-projects github.com hosting service. It seems really good, very nice web UI. After your registration, you obviously need to create any new repository, just follow website’s instructions.

How to push data?

  1. First of all, you need to create any SSH public key. Thats simple way how to trust you. MSysGit can generate key for you – Help -> Show SSH Key -> Generate Key.
  2. Insert the key to your profile at github.com. Click at “Account settings“, choose “SSH Public Keys“. Now, your key is synchronized.
  3. Lets change focus back to MSysGit GUI to upload repository to server.
  4. Select “Remote” item at menu, choose “Add remote“. Fill the location you have already get when you created repository. You can find the url placed at repository overview page. Url has following pattern: git@github.com:{your-user-name/{project-name}.git. After successful filling, the remote github.com repository is paired with your local git repository.
  5. Now, you are able to push the data to remote server. Choose “Remote” -> “Push” and confirm the dialog.

I’m really interested in how I will like the work with Git and right now I really don’t understand  how potential conflicts are solved, I’ll probable see later 🙂