** DevOps Training: https://www.edureka.co/devops **
This Edureka tutorial on "Jenkins pipeline Tutorial" will help you understand the basic concepts of a Jenkins pipeline. Below are the topics covered in the tutorial:
1. The need for Continuous Delivery
2. What is Continuous Delivery?
3. Features before the Jenkins Pipeline
4. What is a Jenkins Pipeline?
5. What is a Jenkinsfile?
6. Pipeline Concepts
7. Hands-On
Check our complete DevOps playlist here (includes all the videos mentioned in the video): http://goo.gl/O2vo13
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Jenkins Pipeline Tutorial | Continuous Delivery Pipeline Using Jenkins | DevOps Training | Edureka
1.
2. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
What Will I Learn Today?
Why Continuous
Delivery?
What is Continuous
Delivery?
Before Jenkins Pipeline
What is a Jenkins
pipeline?
Pipeline Concepts
Create your first
Jenkins Pipeline
Declarative Pipeline Demo
Scripted Pipeline Demo
3. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
FAILURE
Developers
Manual testing
(UT, IT)
Application directly
deployed to prod
Code repo
• Different environments (servers)
• Different libraries & packages (dependencies)
• End user load (traffic)
• App not accessible to intended audience
Why did it fail?
POSSIBLE REASONS
Why Do We Need Continuous Delivery (CD)?
4. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
CD Pipeline
BUILD
CI-Jenkins
(UT, IT)
TEST ENVIRONMENT
(Acceptance testing, Load
testing)
COMMIT
(Version control system (Git))
Production readyDevelopers
5. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Advantages of Continuous Delivery
Automates software release
Increases developer
productivity
Locates and addresses bugs
quicker
6. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
What is CD?
• Continuous Delivery is a practise to continuously (any-time) release
software
• Code changes are continuously built, tested & pushed to a non-
production environment by using automation tools
• Software delivery cycles are more rapid and effective
8. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
HP Future Smart Case Study
HP’s LaserJet firmware division builds firmware that runs all their scanners and printers
• In 2008, they were facing problems, their product delivery cycle was slow
• It took them 6-12 months to build new features; making them slower than all their competitors
Problems
9. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
HP Future Smart Case Study
Single platform to support the whole workflow
Improved quality releases
Faster releases
Solution
10. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
HP Future Smart Case Study
How did they achieve this?
They implemented a CD pipeline
with two key features
• Practice CI
• Automation at every step
• Overall development cost reduced ~ 40%
• Programs under development increased ~ 140%
• Development cost per program went down ~ 78%
12. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Before Jenkins Pipeline
Over the years, there have been multiple Jenkins pipeline releases including, Jenkins Build flow, Jenkins Build Pipeline plugin,
Jenkins Workflow, etc.
What are the key features of these plugins?
These pipelines are a collection of Jenkins jobs which trigger each
other in a specified sequence
Represent multiple Jenkins jobs as one pipeline
What do these pipelines do?
13. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Build Plugin Pipeline Example
• 3 jobs: Job1 → building, Job2 → testing the application and Job3 → deployment
• Chain these jobs together & run using Build Pipeline Plugin (better for small deployment)
14. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Limitations Of The Build Pipeline Plugin
The maintenance cost is huge and increases with the number of processes
Complex pipelines are hard to implement
Tedious to build and manage such a vast number of jobs
16. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
What Is A Jenkins Pipeline?
• Jenkins pipeline is a single platform that runs the entire pipeline as code
• All the standard jobs defined by Jenkins are manually written in one script and they can be stored in a VCS
• Instead of building several jobs for each phase, you can now code the entire workflow and put it in a Jenkinsfile
17. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Key Features Of Jenkins Pipeline
Pipeline as
code
Restart
from saved
checkpoint
Run jobs in
parallel
Integrate
with other
plugins
Allows
conditional
loops (for,
when)
Code can
be checked
into a VCS
Incorporates
user input
19. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
What Is A Jenkinsfile?
A text file that stores the pipeline as code
It can be checked into a SCM on your local
system
Enables the developers to access, edit and
check the code at all times
It is written using the Groovy DSL
Written based on two syntaxes
20. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Two Ways Of Writing Jenkinsfile
DECLARATIVE PIPELINE
• Recent feature
• Simpler groovy syntax
• Code is written locally in a file and is
checked into a SCM
• The code is defined within a ‘pipeline’
block
SCRIPTED PIPELINE
• Traditional way of writing the code
• Stricter groovy syntax
• Code is written on the Jenkins UI
instance
• The code is defined within a ‘node’
block
22. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Pipeline Concepts
Pipeline: A user defined block which contains all the stages. It is a key
part of declarative pipeline syntax.
Node: A node is a machine that executes an entire workflow. It is a key
part of the scripted pipeline syntax.
Note: Stages are explained in the following slides
23. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Pipeline Concepts
Agent: instructs Jenkins to allocate an executor for the builds. It is defined for an entire pipeline or a specific stage.
It has the following parameters:
• Any: Runs pipeline/ stage on any available agent
• None: applied at the root of the pipeline, it indicates that there is no global agent for the entire pipeline & each stage must
specify its own agent
• Label: Executes the pipeline/stage on the labelled agent.
• Docker: Uses docker container as an execution environment for the pipeline or a specific stage.
24. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Pipeline Concepts
Stages: It contains all the work, each stage
performs a specific task.
Steps: steps are carried out in sequence to execute a stage
26. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Create Your First Jenkins Pipeline
Step 1: Log into Jenkins and select New Item from the Dashboard
27. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Create Your First Jenkins Pipeline
Step 2: Next, enter a name for your pipeline and select ‘Pipeline project’. Click ‘ok’ to proceed
28. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Create Your First Jenkins Pipeline
Step 3: Scroll down to the pipeline and choose if you want a Declarative or Scripted pipeline.
29. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Create Your First Jenkins Pipeline
Step 4a: If you want a Scripted pipeline, then choose ‘pipeline script’ and start typing your code
30. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Create Your First Jenkins Pipeline
Step 4b: If you want a Declarative Pipeline, select ‘Pipeline script from SCM’ and choose your SCM. In my case I’m going to use Git
throughout this demo. Enter your repository URL
31. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Create Your First Jenkins Pipeline
Step 5: Within the Script path is the name of the Jenkinsfile that is going to be accessed from your SCM (Git) to run. Finally click
on ‘apply’ and ‘save’. You have successfully created your first pipeline
33. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Declarative Pipeline Demo (Code)
Note: The code is explained in the following slides
34. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Declarative Pipeline Demo (Code)
Note: The code is explained in the following slides
35. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Declarative Pipeline Demo
runs a simple echo command
executes an input directive
runs ‘when’ directive with ‘not’ tag
runs a parallel directive
Stage
1
Stage
2
Stage
3
Stage
4
36. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Declarative Pipeline Demo
The echo command specified in ‘steps’ block,
displays the message
Stage One
runs a simple echo command
Stage Two
executes an input directive
Stage Three
runs ‘when’ directive with ‘not’ tag
Stage Four
runs a parallel directive
37. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Declarative Pipeline Demo
• Input directive allows to prompt a user input in
a stage
• On receiving the user input the pipeline either
proceeds with further execution or aborts
Stage One
runs a simple echo command
Stage Two
executes an input directive
Stage Three
runs ‘when’ directive with ‘not’ tag
Stage Four
runs a parallel directive
38. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Declarative Pipeline Demo
• ‘when’ executes a step depending on the conditions
defined within loop
• If conditions are met, corresponding stage is executed
• In this demo we’re using a ‘not’ tag
• This tag executes a stage when the nested condition
is false
Stage One
runs a simple echo command
Stage Two
executes an input directive
Stage Three
runs ‘when’ directive with ‘not’ tag
Stage Four
runs a parallel directive
39. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Declarative Pipeline Demo
• Runs ‘Unit test’ and ‘Integration test’ stages in
parallel
• ‘Unit Test’ runs an echo command
• In ‘Integration test’ stage, a docker agent pulls an
‘ubuntu’ image & runs the reuseNode which is a
Boolean (returns false by default)
• If true, the docker container will run on the agent
specified at the top-level of the pipeline
Stage One
runs a simple echo command
Stage Two
executes an input directive
Stage Three
runs ‘when’ directive with ‘not’ tag
Stage Four
runs a parallel directive
40. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Declarative Pipeline Demo
Now that I’ve explained the code, lets run the pipeline. The following screenshot is the result of the pipeline.
In the below image, the pipeline waits for the user input and on clicking ‘proceed’ the execution resumes.
41. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Declarative Pipeline Demo
Final output of the Declarative pipeline demo
43. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Scripted Pipeline Demo (Code)
To give you a basic understanding of the scripted pipeline, lets execute a simple code.
I will run the following script
44. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Scripted Pipeline Demo (Code)
• The node block runs the conditional ‘for’ loop for creating 2 stages: Stage #0 & Stage #1
• These stages print ‘hello world!’ message
• ‘if’ loop is used to execute 2 commands when ‘i’ = 0:
‘git’ command to clone the git directory & ‘echo‘ to display a message
• ‘else’ is executed when ‘i’ != 0:
‘build’ executes the job (‘Declarative pipeline’) and then runs the echo command
45. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Scripted Pipeline Demo
Now that I’ve explained the code, lets run the pipeline.
The following screenshot is the result of Stage #0.
46. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Scripted Pipeline Demo
Shows the logs of Stage #1 and starts building the ‘Declarative pipeline’
48. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Scripted Pipeline Demo
Results show the completion of ‘Declarative pipeline’ and Stage #1
49. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
Summary
Pipeline ConceptsWhat is a Jenkinsfile?
Why Continuous Delivery? HP Future Smart Case Study
What is a Jenkins Pipeline?
What Continuous Delivery?
50. DEVOPS CERTIFICATION TRAINING www.edureka.co/devops
WebDriver vs. IDE vs. RC
➢ Data Warehouse is like a relational database designed for analytical needs.
➢ It functions on the basis of OLAP (Online Analytical Processing).
➢ It is a central location where consolidated data from multiple locations (databases) are stored.