yasuoza diary

web and life

Trigger jenkins from Gitlab push hook

Jenkins is awesome secretary and my friend. I can’t live without him.
My Jenkins does these things:

  • Deploy blog.yasuoza.com
  • Test my private repositories
  • Cron jobs

This blog and some private repositories are hosted by my Gitlab.

Today I want to share how to build job via Gitlab push hook with concrete example: how to deploy Octopress blog with Giatlab.

First, you need to configure Octopress with rsync deployment. See more: Configuring Octopress

Next, set jenkins’s public key to blog server so that jenkins can login the server without password.

1
$ sudo -u jenkins -H ssh user@yourhost.com

Then, install Jenkins plugin Gitlab Hook Plugin and set http://your-jenkins-server/gitlab/build_now in your Gitlab like this:

This plugin works even if jenkins requires authentication to enter jenkins home.

NOTE
Gitlab Hook Plugin v0.2.11 does not work well when the job is not parameterized. So, use >= v0.2.12.
For more: Build no longer triggering (Maybe running too bleeding edge?)

Finally, configure Jenkins job to deploy Octopress:

Execute shell
1
2
3
bundle
bundle exec rake generate
bundle exec rake deploy

NOTE
OCTOPRESS REQUIRES RUBY 1.9.3-P194.
Ensure to jenkins’s ruby version is 1.9.3-p194 or use ruby version management framework such as rvm or rbenv.
If you want to let jenkins run not only system ruby, I recomend you to use rbenv plugin.
It is easy to use.

Well, you done. Now push changes to your own Gitlab. Jenkins works for you.

Comments