Successfully reported this slideshow.
You’ve unlocked unlimited downloads on SlideShare!
CI Server Configuration : Jenkins
Continuous integration (CI) is the practice, in software engineering, of merging all
developer working copies with a shared mainline several times a day. It was first named and
proposed by Grady Booch in his method, who did not advocate integrating several times a day..
The main aim of CI is to prevent integration problems, referred to as "integration hell".
CI was originally intended to be used in combination with automated unit tests written
through the practices of testdriven development. Initially this was conceived of as running all
unit tests in the developer's local environment and verifying they all passed before committing to
the mainline. This helps avoid one developer's work in progress breaking another developer's
copy. Later elaborations of the concept introduced build servers, which automatically run the
unit tests periodically or even after every commit and report the results to the developers.
1 Maintain a code repository
2 Automate the build
3 Make the build selftesting
4 Everyone commits to the baseline every day
5 Every commit (to baseline) should be built
6 Keep the build fast
7 Test in a clone of the production environment
8 Make it easy to get the latest deliverables
9 Everyone can see the results of the latest build
10 Automate deployment
Costs and benefits
Continuous integration is intended to produce benefits such as:
Integration bugs are detected early and are easy to track down due to small change
sets. This saves both time and money over the lifespan of a project.
Avoids lastminute chaos at release dates, when everyone tries to check in their slightly
When unit tests fail or a bug emerges, if developer need to revert the codebase to a
bugfree state without debugging, only a small number of changes are lost (because integration
Constant availability of a "current" build for testing, demo, or release purposes
Frequent code checkin pushes developers to create modular, less complex
With continuous automated testing benefits can include:
Enforces discipline of frequent automated testing
Immediate feedback on systemwide impact of local changes
Metrics generated from automated testing and CI (such as metrics for code coverage,
code complexity, and features complete) focus developers on developing functional, quality
code, and help develop momentum in a team
Installing Jenkins on ubuntu
For installation follow below steps:
1. wget q O https://jenkinsci.org/debian/jenkinsci.org.key | sudo aptkey add
2. sudo sh c 'echo deb http://pkg.jenkinsci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
3. sudo aptget update
4. sudo aptget install jenkins
Once installed like this, you can update to the later version of Jenkins (when it comes out) by
running the following commands:
1. sudo aptget update
2. sudo aptget install jenkins
Next, you need to use the Jenkins web interface to install plugins, configure security and add
Open your web browser to http://localhost:8080. (If you’re running Jenkins remotely, you
should be able to use the server’s domain or IP address.)
currently for ip: x.x.x.x
From the root page, click “Manage Jenkins” then “Manage Plugins”. From the “Available”
tab, check the following plugins:
3. rbenv Or rvm
6. RubyMetrics plugin
Next, select “Download now and install after restart”
Configuration of Global Security part is skipped. You can see details here Security
Step 1: Go to yourip:jenkinport/configure (http://x.x.x.x:8080/configure) . You can do it by jenkin
home > manage jenkins > configure system
check home directory is /var/lib/jenkins or not . otherwise you have to set all
default home configuration to that particular home directory.
1. go to yourjenkinserver/configure
2. In Email notification block smtp server => smtp.gmail.com
3. select Use SMTP Authentication
4. give user name password, select use ssh, smtp port => 465 , chracterset =>
5. select Test configuration by sending test email to check configuration is
succesful or not .
6. If fails follow it from above link.
7. Finally under your project settings , In Postbuild Actions in Email notification
set up your emails.
Configure Global Security
1. Enable security.
2. Security Realm > Jenkins’ own user database > Allow users to sign up
3. Authorization > Anyone can do anything
4. after you sign up > change authorization to Loggedin users can do anything or
Matrixbased security or Projectbased Matrix Authorization Strategy as your wish
. in Matrixbased security you can set up configuration for a particular user/ group
which is created in jenkins ui .
N.B. while configuring global security you may have security problem like locking yourself
(Hope you have not :) ).
but If you , then Disable Security
or for your convenience
One may accidentally set up security realm / authorization in such a way that you may no longer
able to reconfigure Jenkins.
When this happens, you can fix this by the following steps:
1. Stop Jenkins (the easiest way to do this is to kill the servlet container.)
2. Go to $JENKINS_HOME in the file system and find config.xml file.
3. Open this file in the editor.
4. Look for the <useSecurity>true</useSecurity> element in this file.
5. Replace true with false
6. Remove the elements authorizationStrategy and securityRealm
7. Start Jenkins
When Jenkins comes back, it's in the unsecured mode where everyone gets full access to the
If this is still not working, trying renaming or deleting config.xml.
Configure your project:
Next, you need to configure your Rails project. To complete this follow below steps:
Step 1: From the Jenkins home page, click on “New Item”, then select “Build a freestyle
software project” and click “OK”.
Step 2: Fill in the “Project Name” and “GitHub project” fields.” Project Name” must be a single
Step 3: Under “Source Code Management”, select “Git” and fill in the repo url. (If you need to
authenticate with SSH, configure that here.)
You need to switch jenkins user to generate ssh key by following command:
su s /bin/bash jenkins
It is because jenkins web interface expect all command will be executed as
a bash command. Hence whenever we executing by switching only by su jenkins
then it’s environment will not same as the jenkins expect. So that the known host
will not allow the user to clone the remote private repository.
Step 4: Check the “rbenv build wrapper” box.
If you are using RVM instead of RBENV then,
Check the Run the build in a RVMmanaged environment =>Implementation
put ruby version for that project.
Step 5: Database credential need to configure to sync the code with jenkin. So that we need to
create database.yml . To do so, follow the below command:
Then you need to write your db config in ~/projectdatabase.yml according to your Database
configuration. To accomplish that follow:
and put your custom configuration in ~/projectdatabase.yml
Tick on Build when a change is pushed to GitHub from Build Triggers
Step 7: Under “Add build step”, select “Execute shell”.
Now we are ready and a typical Rails app script might look like this:
cp ~/projectdatabase.yml config/database.yml
mkdir p coverage/rcov
mkdir p rcov
rake db:create RAILS_ENV=test
rake db:migrate RAILS_ENV=test
Make sure the database is configured properly. If you need a special database.yml, you can
store this in Jenkins’ home directory.
OPTIONAL: To make sure you know when a build fails, set up email notifications (under
“Add postbuild action”). Configure SMTP on the “Configure System” page, found under
“Manage Jenkins”. See the Jenkins wiki for an easy Gmail setup:
Or You can follow below step.
8. got to yourjenkinserver/configure
9. In Email notification block smtp server => smtp.gmail.com
10. select Use SMTP Authentication
11. give user name password, select use ssh, smtp port => 465 , chracterset =>
12. select Test configuration by sending test email to check configuration is
succesful or not .
13. If fails follow it from above link.
14. Finally under your project settings , In Postbuild Actions in Email notification
set up your emails.
1. select publlish rcov report
2. set directory => coverage/rcov
3. Also before do this you need to ensure that you have right gem in your gem file:
gem 'simplecov', :require => false, :group => :test
4. And also configure your spec/spec_helper.rb like this:
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
Try out your build by clicking “Build Now”.
Finally, I'll set up the GitHub integration, so that a push triggers a new build in Jenkins.
Navigate to “Webhooks & Services” under “Settings” on the GitHub repository page.
You’ll need to be a repo admin to do this.
Click “Configure services” and select the “Jenkins (GitHub plugin)” option.
Enter the address to your Jenkins server followed by /githubwebhook/ (for example
http://psdd.t.proxylocal.com/githubwebhook/ or http://x.x.x.x:8080/githubwebhook/ ), check
“Active” and update your settings.
That’s it. Try it out by pushing a commit to GitHub and verifying that a new build is triggered in
As for your hardware questions we do not typically recommend best practices or hardware
configurations because these vary based off specific customer needs and these are considered
consulting questions. Jenkins Enterprise by definition runs exactly the same as OSS Jenkins.
Here are some generic guidelines we sent out to a specific customer that has a sizable config:
The machine requirements on Jenkins installations differ based on the artifacts generated.
Thus, there is no onesize fits all recommendation that we provide. However, here are some
1. Everything runs off JENKINS_HOME, so make sure there is enough disk space
available and the disk can grow. If you run out of disk space, you will see failures. Some
plugins take more space than others (e.g a report generating plugin vs a build plugin).
The disk usage plugin helps determine usage.
2. Have a beefy machine for Jenkins master & do not run slaves on the master machine.
Every slave has certain memory allocated in the master JVM, so the bigger the RAM for
the master, the better it is. We typically hear customers allocate 16G or so.
3. Slaves tend to be run of the mill x86 boxes, typically you want them to have the same
OS as the release platforms.
For reference, this presentation from Redhat shares their typical memory/machine
As for the HA feature this is simply two (or more) masters sharing the same
JENKINS_HOME—you can read more about the plugin here.
To Force restart jenkins
1. sometimes jenkins goes out of memory exception. sudo service jenkins restart
donot work then . to we have to kill the java process manually .
2. sudo netstat lpn | grep :8080 # jenkins run on 8080 port
3. sudo kill 9 pid
4. sudo service jenkins start
User id / Password for test purpose
user : jenkins
password : yourPassword
============== THANK YOU ===============