Jenkins和Gitblit集成实现提交后自动构建
Posted on: 2018-03-30, Last modified: 2018-03-30, View: 2625

Gitblit is a pure Java based git solution. It falls under one of the forge softwares like Apache Allura that combines ticketing system with web ui for git. I went through a process of setting it up and I thought I can help new users avoid the pain points.

Usage scenario

  • You want to self-host git repos
  • You want to setup a Jenkins server to take git repo pushes and run build tests on those branches.
  • You have a domain name and you can set the A Record for it.

Gitblit

  • Easy setup
  • Integrates well with Jenkins
  • Lightweight - compared to Allura or Gitlab
  • Lacks self registration functionality for users

Jenkins CI

  • Easy setup
  • Robust plugin community
  • It's what Circle CI, Travis CI uses for their base stack.

Steps:

  1. Download Gitblit from http://gitblit.com/ For most people you'll want the Gitblit GO.
  2. Follow the installation instructions on the site
  3. Configure the gitblit.properties file in /data directory. Be sure to fill in web.canonicalUrl - it needs to be set for Jenkins integration to work properly.
  4. Download and install Jenkins from http://jenkins-ci.org/
  5. Setup Jenkins as described in https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins
  6. If you installed it as a daemon, launch it ( /etc/init.d/jenkins start )
  7. Go to the url for jenkins. go to Manage Jenkins -> Configure Global Settings -> Enable Security
  8. Turn on 'Allow Users to Signup'
  9. Register and then turn 'Allow Users to Signup' off.

At this point you have both Gitblit and Jenkins set up. But they aren't interacting yet. We want to make it so when we push the commits to gitblit, Jenkins builds it.

  1. Go to the settings in a repo already in your gitblit site. Go to the 'receive' section of the repo setting and add jenkinsto the 'selected' column in the 'post-receive scripts' sub-section.
  2. Go to the /data/groovy directory of Gitblit in your server, edit the jenkins.groovy file. Under jenkinsUrl input your jenkins url.
  3. Restart gitblit.
  4. Login to Jenkins web ui. Go to 'Manage Plugins.' Click on 'Available' and type in Git Plugin into the search box. Install that.
  5. Restart Jenkins.
  6. Also in the plugins are the build environment support plugins. Add those. Specifically for NodeJS, you juse have to be aware that NodeJS plugin's Auto Installation does not show NodeJS dropdown. You have to install by inputting the url of where tar.gz exists. Input the subdirectory that would exist if you unpack it.
  7. Go to Manage Jenkins -> Configure System. Add the proper build environment pre-sets. This is specific to what you want to do. So I leave this out.
  8. Finally, add your build. 'New Item' -> 'Freestyle'
  9. Select git from 'Source Code Management' section. Put the url and other settings. I usually have two build projects made for each git project. One for <projectName>-Release, and one for <projectName>-All. I set it up so the branch setting in Jenkins is blank for <projectName>-All project. That way all feature and dev branches are built and tested.
  10. Next, select 'Poll SCM' and leave it blank. Gitblit's Jenkins groovy plugin will call the Jenkins' hook for building on-demand this way. A way to verify is to try curl <jenkinsUrl>/git/notifyCommit?url=<gitblitUrl>/r/<repoName> or you can also just put that in the browser as well.
  11. If you want links to those cool 'build status' image as well, install embeddable-build-status plugin for Jenkins. After that, link it in your website or markdown docs.

Congratulations, you now have Gitblit and Jenkins CI set up to take the git commit pushes and build them!

From: https://voat.co/v/programming/comments/372494
Go
Friend Links:
Bill Site
https://item.taobao.com/item.htm?spm=a21an.7676007.1998473182.296.lAvrE2&id=45399580446