Jenkins, the CI.
CI here is not an abbreviation for Confidential Informant but for Continuous Integration. In the sequel, I will discuss how to build the CI environment with Jenkins + Github.
Target sbt project
Here is a sample sbt project with specs2 testing framework. I will use this project as a CI target.
name := "expmtlSbtSpecs2" version := "1.0" scalaVersion := "2.9.1" resolvers ++= Seq( "Specs2 Repo" at "http://oss.sonatype.org/content/repositories/releases" ) libraryDependencies := Seq( "org.specs2" %% "specs2" % "1.11" % "test", "org.scala-tools.testing" %% "scalacheck" % "1.9", "org.mockito" % "mockito-all" % "1.9.0" )
Installing Jenkins on Community Enterprise OS 6
Adding jenkins.repo to rpm.repo
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
Installing Jenkins via yum
yum install jenkins
Starting up Jenkins
sudo /etc/init.d/jenkins start
Now your Jenkins is listenning to port 8080. Go to http://yourhost:8080. Jenkins will be compiled when the first access has made, so it may take some time before you see the rendered page. Now we move to configuration of Jenkins. There are 2 kinds of configuration:
- Global Settings
- Project Settings
In the Global Settings
[Jenkins Home -> Manage Jenkins -> Configure System]
we configure Git path, JDK path, SBT path ... something that Jenkins uses for CI.
In the Project Settings
[Jenkins Home -> Project Page -> Configure ]
we configure project build options, github repository ... something depending to the project.
Activating Security
By the default setting, anybody has full access to the Jenkins, which means anybody create jobs and run the build. That's no good at all. Running builds consume a lot of resources. We need to restrict certain actions to certain users. To do that, go to
[Manage Jenkins -> check Enable Security]
And configure followings:
Security Realm
- check Jenkins's user database
- check Allow users to sign up
Authorization
- check Matrix-based security
Add user by using
[User/group to add:]
- check all attributes for your username (an administrator)
- Do not forget to check Read[Overall] for Anonymous
Installing plugins.
I'm going to create the job that build sbt project I defeined previously. Jenkins will build the project and run the test when changes are pushed to the configured github repository. Firstly, we need plugins to build the sbt project and synchronize with github. Go to
[ Jenkins Home -> Manage Jenkins -> Manage Plugins ]
And install the following:
- Jenkins sbt plugin
- Github plugin
Configuring plugins.
Now we need to configure plugins we installed previously in order to make sure these work correctly.
Go to
[Jenkins Home -> Manage Jenkins -> Configure System]
Sbt
Descriptor | value |
Name | sbt |
Path | /path/to/sbt-launch.jar |
Global Github setting.
Here you need to set WebHook. Basically what this does is that if you push to github repo, github POST the JSON to Jenkins so the Jenkins know that changes are made.
Go to
[Jenkins Home > Manage Jenkins -> Configure System]
GitHub Web Hook
Descriptor | value |
Let Jenkins auto-manage hook URLs | selectected |
Override Hook URL | http://yourdomain/github-webhook/ |
GitHub Credentials | set your github account and password |
Create a new job
Now we are going to make a new job. To make a new job,
[Jenkins Home -> New Job]
Select [Build a free-style software project] and click [OK].
Configuring the job.
Now we are going to configure the job we made previously. Go to the Jenkins home and you will find the project. Go to the project page and go to [Configure]. Following is the settings you want.
General
Descriptor | value |
Project name | Your Project Name |
GitHub project | https://github.com/username/YourProject/ |
Source Code Management
Descriptor | value |
Git | https://github.com/username/YourProject.git |
Branches to build | develop / master / * / ** etc |
Build Triggers
Descriptor | value |
Build when a change is pushed to GitHub | checked |
Build
Descriptor | value |
sbt | selected |
JVM Flags | -Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=384M |
sbt Flags | -Dsbt.log.noformat=true |
Action | clean test |