jenkins ci

15
Jenkins CI Ruchi Agarwal Sr Software Consultant Knoldus Software LLP

Upload: knoldus-software-llp

Post on 15-Jul-2015

1.038 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Jenkins CI

Jenkins CI

Ruchi AgarwalSr Software ConsultantKnoldus Software LLP

Page 2: Jenkins CI

Index:

About Jenkins CI

Install Jenkins

Configure Jenkins Job (Git/ Assembla)

Schedule Jenkins job

Post Build Actions : Extended E-mail Notification

Web Hooks (Git/ Assembla)

Matrix-based Security

Page 3: Jenkins CI

About Jenkins:

- Jenkins is an open source continuous integration (CI) tool written in Java.

Continuous integration (CI) is the practice, in software engineering, of merging all developer working copies with a shared mainline several times a day. The main aim of CI is to prevent integration problems

- Jenkins provides continuous integration services for software development. It is a server-based system running in a servlet container such as Apache Tomcat.

- It supports SCM tools including AccuRev, CVS, Subversion, Git, Mercurial, Perforce, Clearcase and RTC, and can execute Apache Ant and Apache Maven based projects as well as arbitrary shell scripts and Windows batch commands.

- Builds can be started by various means, including being triggered by commit in a version control system, scheduling via a cron-like mechanism, building when other builds have completed, and by requesting a specific build URL.

Page 4: Jenkins CI

Install Jenkins

- Download Jenkins.war file:

$ wget http://ftp-chi.osuosl.org/pub/jenkins/war/1.592/jenkins.war

- Run Jenkins:

$ java -jar jenkins.war

- By default, Jenkins listen on port 8080. Access this port with browser to start configuration

Command Line Parameters

- To change port numer:

$ java -jar jenkins.war --httpPort=$HTTP_PORT

- Binds Jenkins to the specific IP address (deafult is 0.0.0.0)

$ java -jar jenkins.war --httpListenAddress=$HTTP_HOST

- Runs Jenkins to include the $PREFIX at the end of the URL

$ java -jar jenkins.war --prefix=$PREFIX

Page 5: Jenkins CI

Configure a Jenkins Job : Git and Assembla

- Under ‘Manage Jenkins’ -> ‘Manage Plugins’, select and install following plugins:• Github and Git plugins• Assembla and Assembla Auth Plugin

- Restart after finish the installation. After this is installed either create a new build or configure an existing build job- Add github repository path

-> In "Source Code Management" select "Git" a) Provide Repository URL b) Credentials of Repositories for private repository (login access/ SSH key)c) Branch to build (i.e. branchName)

Page 6: Jenkins CI

- Add a Build step to the Execute shell command. This gives the ability to define a bash script to perform build execution

- Save changes and Run a build.

- Jenkins clone the project in its workspace and after that execute provided shell command script

Page 7: Jenkins CI

Schedule Jenkins Job

- Under “Configure” -> “Build trigger” give the time in cron syntax for triggering a job automatically in Jenkins

Examples:

• */1 * * * * : Every minute• 0 0 1 * * : Once in a day• 0 0 * * 0 : Once in a week• 0 0 * * * : Once in a day

Page 8: Jenkins CI

Post Build Actions : Extended E-mail Notification

- Jenkins privides post build actions which executes after the jenkins build. Jenkins allows to have email notification for successful or failed build.

- Install “Manage Jenkins” -> “Manage plugins” -> ”Email-ext plugin"

- Go to Manage Jenkins -> Configure System -> a) In Jenkins Location provide "System Admin E-mail Address"

b) Extended E-mail Notification : Set up mail subject and contents settings

Page 9: Jenkins CI

- In E-mail Notifications provide smtp mail server configuration

- Save the changes

- Go to Project Configuration -> Post Build Action -> Select "Editable E-mail Notifications"

- Provide email id of people in "Project recipients list", Attach Build Log (This document would contain complete build report and would be attached with Email)

- In "Advanced Settings" option, Set "Triggers" to "Always". This would sent notifications for every successful and failed build with complete logs.

- Save the changes

Page 10: Jenkins CI

WebHook

A WebHook is an HTTP callback: an HTTP POST that occurs when something happens or a simple event-notification via HTTP POST.

Build Jenkins Job on Git Commit

- With the latest Git plugin 1.1.14, can do this more easily by simply executing the following command:

curl http://yourserver/jenkins/git/notifyCommit?url=<URL of the Git repository>

- This will scan all the jobs that’s configured to check out the specified URL, and if they are also configured with polling, it’ll immediately trigger the polling (and if that finds a change worth a build, a build will be triggered in turn.)

- Follow the follwoing steps to set-up: Go to “Configure” -> “Build Trigger” Check “Poll SCM” : Leave the schedule field empty Now, go to “Settings” page of your github repository (http://github.com/

<user_id>/<project_name>/settings) Search for “Jenkins (Git Plugin)” under “Webhooks & Services” -> “Services” -> “Add

services”

Page 11: Jenkins CI

Provide Jenkins url. "Jenkins Url" is the base URL of Jenkins server

This willl hit /git/notifyCommit under github repository URL

- Add service and That's It

- Commit the changes. This will trigger jenkins job

Page 12: Jenkins CI

WebHook with Assembla

- Add a Webhook tool via the Admin → Tools on the Assembla home screen (this action requires to have admin rights)

- Create a new Webhook with the following options:Title : ‘Jenkins Commit’ or any; Authentication type: Basic;

External url: {IP address of your jenks server}/git/notifyCommit?url=%{repository_url};Http metod: Get; Content type – text/plain; Leave the content field empty and tick ‘Code commits’ at ‘Post updates about’ section.

Page 13: Jenkins CI

Matrix-based security

- Matrix-based security is one of the authorization strategies available for securing Jenkins.

- It allows to grant specific permissions to users and groups. Follow the following steps to enable security:

Activate “Enable Security” under “Manage Jenkins” -> “Configure Global Security”

Select “Jenkins’ own user database” from “Security Realm” and activate jenkins sign up

Page 14: Jenkins CI

Select “Matrix-based security” and set the permissions to user/ group

- Save changes

Page 15: Jenkins CI