Integration of Jenkins and GitBlit

3.8k Views Asked by At

Is there a way to configure Jenkins and GitBlit so that builds are run automatically whenever a new code is pushed to git?

I've heard about using hook and post-jenknkins scripts in GitBlit and configuring 'Poll SCM' in Jenkins but perhaps there are more sophiscated configurations?

Thanks a lot.

1

There are 1 best solutions below

0
On

There are two ways to use Jenkins and GitBlit to build your code. The first is to have Jenkins poll your SCM (GitBlit in this case) for changes, and the second is to set up a post-receive hook in Gitblit.

Polling GitBlit for changes is the simplest to set up but comes with additional overhead on the server Jenkins is running on. The basic premise is Jenkins will clone your repo and compare against its previous clone to look for changes. If there is a difference it triggers a build. With many jobs and several repositories this could really tax your jenkins server and possibly the gitblit server as well. To set this up simply check the Poll SCM box and choose a schedule. The schedule field uses cron syntax and clicking on the ? next to the field will provide you with an example.

Setting up a post-receive hook is more complicated but provides you with true build-on-commit semantics. Now there are two ways to do this in Jenkins, Remote Trigger or use Gitblit's jenkins hook. Remote Trigger requires you to create a token for each job that is then sent to the job. Since this token is specific to the job Jenkins is building you'll have add a new job/token pair for each job running against each repository. While this isn't a resource waste for Jenkins or GitBlit, it does waste your time maintaining these pairs.

GitBlit's jenkins hook is simple and you can use it either globally or for specific repositories. To enable this, edit jenkins.groovy found in ${appserver.base}/groovy where ${appserver.base} is where ever you set that to be during installation. Edit the def jenkinsUrl = gitblit.getString('groovy.jenkinsServer', 'http://your/jenkins/url') line with the URL of your Jenkins server. You could also just set the groovy.jenkinsServer in your gitblit.properties file. To force all repositories to use this hook script add it to the groovy.postReceiveScripts line in your gitblit.properties file. Otherwise edit your repository in the GitBlit web app and add jenkins to its post-receive hook list.