Jenkins Cheat Sheet 002
Jenkins Cheat Sheet 002
Jenkins Cheat Sheet 002
edureka.co/blog/cheatsheets/jenkins-cheat-sheet
Installation
1/8
Let’s start by installing Jenkins. This installation is specific to systems operating on
Ubuntu. Follow the below steps:
Maven
Git
Ant
Docker
Amazon EC2
HTML publisher
Copy artifact
Follow the below step to install the above plugins or any other Jenkins plugin.
Jenkins Dashboard -> Manage Jenkins -> Manage Plugins -> Available
In the filter text field enter the name of the plugin you want to install.
Freestyle
Freestyle build jobs are general-purpose build jobs, which provides maximum flexibility.
It can be used for any type of project.
2/8
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.
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.
Folder
This project allows users to create folders to organize and categorize similar jobs in one
folder or sub folder.
GitHub Organization
This project scans your entire GitHub organization and creates Pipeline jobs for each
repository containing a Jenkinsfile
Multibranch pipeline
This project type lets you implement different Jenkinsfiles for different branches of the
same project.
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
In the filter text field enter the name of the plugin you want to install.
3/8
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:
Scripted pipeline
Code is written on the Jenkins UI instance and is enclosed within the node block
node {
scripted pipeline code
}
Declarative pipeline
Code is written locally in a file and is checked into a SCM and is enclosed within the
pipeline block
pipeline {
declarative pipeline code
}
Pipeline Concepts
The below fundamentals are common to both, scripted and declarative pipeline:
1. Pipeline: A user defined block which contains all the stages. It is a key part of
declarative pipeline syntax.
2. Node: A node is a machine that executes an entire workflow. It is a key part of the
scripted pipeline syntax.
3. Agent: instructs Jenkins to allocate an executor for the builds. It is defined for an
entire pipeline or a specific stage.
4/8
It has the following parameters:
4. Stages: It contains all the work; each stage performs a specific task.
5. Steps: steps are carried out in sequence to execute a stage
Follow the below steps to create both, a scripted pipeline and a declarative pipeline:
Step 1: Log into Jenkins and select ‘New Item from the Dashboard'
Step 2: Next, enter a name for your pipeline and select ‘Pipeline project’. Click
‘ok’ to proceed
Step 3: Scroll down to the pipeline and choose if you want a Declarative or
Scripted pipeline
Step 4a: If you want a Scripted pipeline, then choose ‘pipeline script’ and start
typing your code
Step 4b: If you want a Declarative Pipeline, select ‘Pipeline script from SCM’ and
choose your SCM and enter your repository URL
Step 5: Within the Script path is the name of the Jenkinsfile that is going to be
accessed from your SCM to run. Finally click on ‘apply’ and ‘save’
5/8
node {
stage(‘SCM checkout’) {
//Checkout from your SCM(Source Control Management)
//For eg: Git Checkout
}
stage(‘Build’) {
//Compile code
//Install dependencies
//Perform Unit Test, Integration Test
}
stage(‘Test’) {
//Resolve test server dependencies
//Perform UAT
}
stage(‘Deploy’) {
//Deploy code to prod server
//Solve dependency issues
}
}
6/8
Syntax: (Minute Hour DOM Month DOW)
Snippet Generator
A tool that lets users generate code for individual steps in a scripted pipeline. Let’s look at
an example:
Below is an image of the Snippet Generator. You can select from a variety of steps and
generate a code for each step.
7/8
Below is an image of the Scripted pipeline UI with the code generated from snippet
generator
8/8