Jenkins Cheat Sheet-PART 1

Sri Priya P Kulkarni
3 min readJul 3, 2023

--

What is Continuous Integration?

Continuous Integration is a software development practice in which developers are required to frequently commit changes to the source code in a shared repository. Each commit is then continuously pulled & built. Jenkins is an open source, Continuous Integration (CI) tool, written in Java. It continuously pulls, builds and tests any code commits made by a developer with the help of plugins.

Install Jenkins on Ubuntu

This installation is specific to systems operating on Ubuntu.

Follow the below steps:

Step 1: Install Java $ sudo apt update

$ sudo apt install openjdk-8-jdk

Step 2: Add Jenkins Repository

$ wget -q -O — https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add —

Step 3: Add Jenkins repo to the system

$ sudo sh -c ‘echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list’

Step 4: Install Jenkins

$ sudo apt update $ sudo apt install Jenkins

Step 5: Verify installation

$ systemctl status Jenkins

Step 6: Once Jenkins is up and running, access it from the link: http://localhost:8080

Build Pipeline

Build pipeline can be used to chain several jobs together and run them in a sequence.

Let’s see how to install Build Pipeline:

Jenkins Dashboard-> Manage Jenkins-> Manage Plugins-> Available-> Build Pipeline

Build Pipeline Example:

Step 1: Create 3 freestyle Jobs (Job1, Job2, Job3)

Step 2: Chain the 3 Jobs together

Job1 ->configure ->Post Build ->Build other projects ->Job2

Job2 ->configure ->Post Build ->Build other projects ->Job3

Step 3: Create a build pipeline view Jenkins Dashboard ->Add view ->Enter a name ->Build pipeline view ->ok ->configure ->Pipeline flow ->Select Initial job ->Job1 ->ok

Step 4: Run the Build Pipeline

Different type of Jenkins Jobs

Jenkins provides the option of choosing from different types of jobs to build your project.

  1. Freestyle Job

Freestyle build jobs are general-purpose build jobs, which provides maximum flexibility. It can be used for any type of project.

2. Pipeline

This project runs the entire software development workflow as code. Instead of creating several jobs for each stage of software development, you can now run the entire workflow as one code.

3. Multiconfiguration

The multiconfiguration project allows you to run the same build job on different environments. It is used for testing an application in different environments.

4. Folder

This project allows users to create folders to organize and categorize similar jobs in one folder or sub folder.

5. GitHub Organisation

This project scans your entire GitHub organization and creates Pipeline jobs for each repository containing a Jenkins file

6. Multibranch Pipeline

This project type lets you implement different Jenkins files for different branches of the same project.

Jenkins Pipeline

Jenkins pipeline is a single platform that runs the entire pipeline as code. Instead of building several jobs for each phase, you can now code the entire workflow and put it in a Jenkinsfile.

Jenkinsfile is a text file that stores the pipeline as code. It is written using the Groovy DSL.

It can be written based on two syntaxes:

  1. Scripted pipeline: Code is written on the Jenkins UI instance and is enclosed within the node block
Scripted Pipeline

2. Declarative pipeline:

Code is written locally in a file and is checked into a SCM and is enclosed within the pipeline block

Declarative Pipeline

Jenkins Pipeline Syntax Example

Jenkins Pipeline Example

I hope you liked the PART 1 of Jenkins Cheat Sheet, will publish some tips and tricks of handling Jenkins Pipeline in PART 2.

Thanks for reading!!!

Happy Testing!!!

--

--

Sri Priya P Kulkarni
Sri Priya P Kulkarni

Written by Sri Priya P Kulkarni

SDET| Blogger! | Automation Enthusiast! | On a journey of Continuous learning.... !

No responses yet