1 of 27

Unit 1

Jenkins is a very powerful Build Engine used in CI/CD. What makes it powerful is the set of plugins and its integration with a lot of other tools including Docker.

Presented by – Seshagiri Sriram

Getting Started with Jenkins and CI/CD powered by Docker

2 of 27

Agenda

  • A quick overview of CI/CD
  • Benefits of Jenkins
  • Jenkins Eco-System
  • Installation of Jenkins
  • Integrating Jenkins with GitHub
  • Creating your first pipeline
  • Automating the Build/Test/Deploy Pipeline
  • Items marked in yellow are covered in Hands On Lab

www.guvi.in

2

3 of 27

What is CI/CD

  • Martin Fowler defines Continuous Integration (CI) as
  • A Software Development Process where
  • Every team member merge their changes along
  • With changes from other team members
  • At least once daily
  • Each of these integrations are verified by automated builds
  • (including Tests)
  • To detect errors early on in the process

www.guvi.in

3

4 of 27

Do we have data?

www.guvi.in

4

5 of 27

CI – The origins

www.guvi.in

5

6 of 27

A basic flow for CI

www.guvi.in

6

JENKINS

GITHUB

7 of 27

CI vs Build Management

www.guvi.in

7

8 of 27

CI is not just Compiling Code!

  • CI is not the same as a build
  • The latter term is used for compilation only
  • CI includes
    • Compilation
    • Running Unit tests
    • Generating Documents and Reports
    • Integrating Databases
    • Running System/Integration/Regression/Security Test
    • Integrate with Continuous Delivery (CD) for deployment

www.guvi.in

8

9 of 27

Simplified CI/CD Pipeline

www.guvi.in

9

Commit Code

Unit and Integration Test

Continuous Integration

Deploy to Test Environment

Acceptance Testing

Continuous Delivery

Deploy to Production

Continuous Deployment

10 of 27

Continuous Integration Basics

www.guvi.in

10

Dedicated Build Server

Developer Workstations

Code Changes

Version Control Server

Integration Server

Test Server

UAT Server

Production Server

Auto Deployment Process

  • Compilation
  • Test Execution
  • Database integration
  • Code inspection
  • Automated Deployment
  • Document Generation

11 of 27

So can I use Jenkins as is?

  • Yes
  • However to be effective
    • You need defined processes & tools for Version Control
    • You should have automated test cases ready
    • You need defined processes & tools for building and deployment
    • You need JENKINS
  • All should be scriptable.
  • Very Minimal GUI/user interaction

www.guvi.in

11

12 of 27

Alternatives to Jenkins

www.guvi.in

12

Hudson

NB: Hudson later became Jenkins

13 of 27

Why Jenkins?

  • Open Source
  • Commercial and Enterprise Edition/Support available
  • Extensible with over 1000+ plugins for integration
  • Can be extended with custom plugin if required
  • Easy to Install
  • Can be run as Docker Container
  • Can be used with most programming languages
  • Web based Admin

www.guvi.in

13

14 of 27

Jenkins Plugins

  • The of Jenkins are plugins.

  • Jenkins has over 800+ Plugins.
    • It was over 1000, but many have been pruned and merged for better user experience

  • See here: https://plugins.jenkins.io/

www.guvi.in

14

15 of 27

One way of looking at plugins

www.guvi.in

15

Plugins

SCM

Build Triggers

Build Tools

Build Wrappers

Notifiers

Report Plugins

Plugins

Slave Controllers

Artifacts Uploaders

UI Plugins

List View Column Plugins

External Tool Integrators

Other Post Build Tools

16 of 27

Plugins

  • The system administrator can choose what plugins to install.
  • Note that plugins can be uninstalled at any time
    • A good way to learn about each plugin

www.guvi.in

16

A Note on Jenkins Practice

  1. When installing, we choose default plugins when first exploring Jenkins
  2. On first Login, Navigate to Manage Jenkins->Plugins and update all plugins (esp. If installing as a Java WAR file)

17 of 27

Plugins vs Build Tools

  • Jenkins does not compile or test code itself.
  • It provides support for these via Tools where the administrator installs
    • Java
    • Maven
    • Ant
    • … Some other java related tools
    • GIT clients

www.guvi.in

17

18 of 27

Plugins vs Build Tools

www.guvi.in

18

A Note on Jenkins Practice

  1. Rather than configuring these tools in the main Jenkins server, these are usually delegated to docker images that contain these tools
  2. Another approach (preferred) is to delegate these tasks to a slave node.

A Note on Jenkins Practice

  1. The 1st time Jenkins is launched, it has no security.
  2. DO NOT EXPOSE URL to the rest of the world before setting security.

19 of 27

www.guvi.in

19

Lab Time

20 of 27

Masters & Slaves

  • The Jenkins Server is considered a master node.
  • Its label is set to Docker to enable it to spin a docker container on demand.
  • Sometimes, it may be necessary to have tasks be run on a dedicated machine e.g. Windows apps.
  • Such nodes are designated Jenkins Slaves.

www.guvi.in

20

21 of 27

Masters and Slaves

www.guvi.in

21

22 of 27

Masters & Slaves

  • The only considerations are
    • Masters and slaves should be as close as possible in network
    • SSH communication should be enabled between the master and slave
    • Install the required plugins

www.guvi.in

22

23 of 27

Masters & Slaves

  • The only considerations are
    • Masters and slaves should be as close as possible in network
    • SSH communication should be enabled between the master and slave
    • Install the required plugins

www.guvi.in

23

24 of 27

Masters & Slaves

www.guvi.in

24

25 of 27

Masters & Slaves

  • On the Slave (Java),
    • Install Java and Jenkins Slave Jar
    • Copy over Masters’ Public Key to authorized_keys file under .ssh
  • On Master,
    • Create a SSH credential for user running the agent
    • Add the user’s public key to the authorized_keys
    • Validate that ssh commands do not ask for password or prompts
    • Now configure the nodes to use the credential and assign jobs to the slave nodes.

www.guvi.in

25

26 of 27

www.guvi.in

26

Q &A

27 of 27

www.guvi.in

27

We're done!

Thank you for your time and participation.