0% found this document useful (0 votes)
6 views45 pages

Introduction to Jenkins

Jenkins is a widely-used open-source tool for Continuous Integration and Continuous Deployment, facilitating software development by allowing developers to integrate code changes frequently. It supports various automation tools through a rich ecosystem of over 1000 plugins, enabling continuous testing and delivery of software. The tool utilizes pipelines, which can be declarative or scripted, to model and automate the software delivery process, enhancing collaboration and efficiency in development teams.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views45 pages

Introduction to Jenkins

Jenkins is a widely-used open-source tool for Continuous Integration and Continuous Deployment, facilitating software development by allowing developers to integrate code changes frequently. It supports various automation tools through a rich ecosystem of over 1000 plugins, enabling continuous testing and delivery of software. The tool utilizes pipelines, which can be declarative or scripted, to model and automate the software delivery process, enhancing collaboration and efficiency in development teams.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 45

Jenkins

What is Jenkins
What is Jenkins
─ Jenkin is the most popular, open source Continuous Integration and Continuous Deployment Tool.
─ Continuous Integration : is a development practice that requires developers to integrate code into a shared repository
several times a day. It will have multiple integrations with various AU Tools.
─ Continuous Deployment : is the process that takes validated Features in a staging environment and deploys them into
the production environment.
─ Jenkins is used to build and test your software projects continuously making it easier for developers to integrate changes
to the project.
─ It also allows you to continuously deliver your software by integrating with a large number of testing and deployment
technologies.
─ Jenkins achieves Continuous Integration with the help of plugins. Plugins allow the integration of Various DevOps stages.

3 © Atos|Syntel - For internal use


CI/CD

4 © Atos|Syntel - For internal use


Jenkins

5 © Atos|Syntel - For internal use


Advantages of Jenkins
─ It is an open-source tool with great community support.
─ It is easy to install.
─ It has 1000+ plugins to ease your work. If a plugin does not exist, you can code it and share it with the community.
─ It is free of cost.
─ It can connect with various Automation Tools.

6 © Atos|Syntel - For internal use


Workflow

7 © Atos|Syntel - For internal use


What is Plugins
─ Plug-in, also called add-on or extension
─ plug-in is a software component that adds a specific feature to an existing computer program.
─ Plugins are the primary means of enhancing the functionality of a Jenkins environment to suit organization- or user-
specific needs.
─ There are over a thousand different plugins which can be installed on a Jenkins controller and to integrate various build
tools, cloud providers, analysis tools, and much more.

8 © Atos|Syntel - For internal use


Jenkins Dashboard

9 © Atos|Syntel - For internal use


Dashboard functions

10 © Atos|Syntel - For internal use


Dashboard functions
─ New Item – This is a Jenkins feature by using it we create free style jobs (simple job) pipeline jobs (complex), multi-
branch pipeline, multi configuration, external job etc..
─ People – People feature provide list of users and their commit activity info.
─ Build History - Job and their build status.
─ Project Relationship – This is basically use for project dependencies, chaining.
─ Check File Fingerprint – This is for to track dependencies.
─ Manage Jenkins – It handles other sub features like plugin dependencies, configuration system, Global tool
configuration, security settings, User mgmt and Jenkins status information.
─ My view – If you have any other custom view, you can set otherwise it will show default view.
─ Blue Ocean – Different User Interface for Jenkins.

11 © Atos|Syntel - For internal use


Dashboard functions
─ Lockable resource - This plugin allows defining lockable resources (such as printers, phones, computers, etc.) that can be
used by builds. If a build requires a resource which is already locked, it will wait for the resource to be free.
─ New view – It will render to open new Jenkins portal with different view.

12 © Atos|Syntel - For internal use


Manage Jenkins Functions
─ Manage Jenkins  Configure System - It holds the configuration of sonar server, nexus servers and their integration with
Jenkins server configuration and another config like maven project configuration.

13 © Atos|Syntel - For internal use


Manage Jenkins Functions
─ Manage Jenkins  Global Tool Configuration – This setting manages global tools settings for all projects or jobs like git,
java settings, maven, and automatic installation of tools.

14 © Atos|Syntel - For internal use


Manage Jenkins Functions
─ Manage Jenkins  Plugin Manager – This setting manages updates for installed plugins, you can install plugins from
available section to search required plugin and then after installation you should click on Install without restart.

15 © Atos|Syntel - For internal use


Manage Jenkins Functions
─ Manage Jenkins  You will see Security and their sub sections like Global security, manage credentials, Manage users,
credentials provider – This sections manages user and security management part.

16 © Atos|Syntel - For internal use


What is Pipeline?
─ Pipeline is a collection of events or jobs which are interlinked with one another in a sequence.
─ It is a combination of plugins that support the integration and implementation of continuous delivery pipelines using
Jenkins.
─ Jenkins Pipeline is a collection of jobs or events that brings the software from version control into the hands of the end
users by using automation tools.
─ Pipeline provides an extensible set of tools for modeling simple-to-complex delivery pipelines "as code" via the pipeline
domain-specific language syntax (DSL).

17 © Atos|Syntel - For internal use


Benefits of Pipeline
─ Automatically creates a Pipeline build process for all branches and pull requests.
─ Code review/iteration on the Pipeline (along with the remaining source code).
─ Audit trail for the Pipeline.
─ Single source of truth for the Pipeline, which can be viewed and edited by multiple members of the project.

18 © Atos|Syntel - For internal use


Types of pipeline
─ Generally we have two types of pipelines
─ Declarative Pipeline
─ Scripted Pipeline
─ A Jenkinsfile can be written using two types of syntax - Declarative and Scripted.
─ Jenkinsfile: just a text file and It contains Pipeline scripts for running the pipeline with multiple stages.

19 © Atos|Syntel - For internal use


Why Pipeline?
─ Code: Pipelines are implemented in code and typically checked into source control, giving teams the ability to edit,
review, and iterate upon their delivery pipeline.
─ Durable: Pipelines can survive both planned and unplanned restarts of the Jenkins controller.
─ Pausable: Pipelines can optionally stop and wait for human input or approval before continuing the Pipeline run.
─ Versatile: Pipelines support complex real-world CD requirements, including the ability to fork/join, loop, and perform
work in parallel.
─ Extensible: The Pipeline plugin supports custom extensions to its DSL and multiple options for integration with other
plugins.

20 © Atos|Syntel - For internal use


Pipeline Workflow

21 © Atos|Syntel - For internal use


Declarative Pipeline
─ Declarative Pipeline is a more recent feature of Jenkins Pipeline
─ It is providing richer syntactical features over Scripted Pipeline syntax
─ Declarative pipeline syntax is designed to make writing and reading Pipeline code easier.
─ A valid Declarative pipeline must be defined with the “pipeline” sentence.
 Agent
 Stages
 Stage
 Steps
 environment (Defined at stage or pipeline level)
 input (Defined at stage level)
 options (Defined at stage or pipeline level)
 parallel

22 © Atos|Syntel - For internal use


Declarative Pipeline
 Parameters
 Post
 Script
 Tools
 Triggers
 When

─ Agent:
─ Jenkins provides the ability to perform distributed builds by delegating them to “agent” nodes.
─ Doing this allows you to execute several projects with only one instance of the Jenkins server, while the workload
is distributed to its agents.

23 © Atos|Syntel - For internal use


Declarative Pipeline
Ex:
pipeline {
agent any
...
}
─ Stages:
─ This section allows to generate different stages on your pipeline that will be visualized as different segments when
the job is run.
Ex:
pipeline {
agent any
stages {
...
}
}
24 © Atos|Syntel - For internal use
Declarative Pipeline
─ Stage:
─ At least one “stage” section must be defined on the “stages” section. It will contain the work that the pipeline will
execute.
─ Stages must be named accordingly since Jenkins will display each of them on its interface.
Ex:
pipeline {
agent any
stages {
stage ('build') {
...
}
stage ('test: integration-&-quality') {
...
}
stage ('test: functional') {
...
}}

25 © Atos|Syntel - For internal use


Declarative Pipeline
─ Steps:
─ The last required section is “steps”, which is defined into a “stage”. At least one step must be defined in the “steps”
section.
Ex:
steps {
sh 'echo "A one line step"'
sh '''
echo "A multiline step"'
cd /tests/results
'''
}

26 © Atos|Syntel - For internal use


Declarative Pipeline
─ Environment:
─ This directive can be both defined at stage or pipeline level, which will determine the scope of its definitions.
─ When “environment” is used at the “pipeline” level, its definitions will be valid for all of the pipeline steps. If
instead it is defined within a “stage”, it will only be valid for the particular stage.
Ex:
pipeline {
agent any
environment {
OUTPUT_PATH = './outputs/'
}
stages {
stage ('build') {
...
}
...
}
}

27 © Atos|Syntel - For internal use


Declarative Pipeline
─ Input:
─ The "input" directive is defined at a stage level and provides the functionality to prompt for an input. The stage will
be paused until a user manually confirms it.
Ex:
pipeline {
agent any
stages {
stage ('build') {
input 'input message'
}}
}

28 © Atos|Syntel - For internal use


Declarative Pipeline
─ Options:
─ Defined at pipeline level, this directive will group the specific options for the whole pipeline. The available options
are:
 buildDiscarder
 disableConcurrentBuilds
 overrideIndexTriggers
 skipDefaultCheckout
 skipStagesAfterUnstable
 checkoutToSubdirectory
 newContainerPerStage
 Timeout
 retry

29 © Atos|Syntel - For internal use


Declarative Pipeline
Ex:
pipeline {
agent any
options {
retry(3)
}
stages {
...
}
}

30 © Atos|Syntel - For internal use


Declarative Pipeline
─ Parallel:
─ Jenkins pipeline Stages can have other stages nested inside that will be executed in parallel. This is done by adding
the “parallel” directive to your script.

31 © Atos|Syntel - For internal use


Declarative Pipeline

Ex:
pipeline {
agent none
stages {
stage('Run Tests') {
parallel {
stage('Test On Windows') {
agent { label "windows" }
steps {
bat "run-tests.bat"
}
}
stage('Test On Linux') {
agent { label "linux" }
steps {
sh "run-tests.sh"
}}}}
}
}

32 © Atos|Syntel - For internal use


Declarative Pipeline
─ Parameters:
─ This directive allows you to define a list of parameters to be used in the script.
─ Parameters should be provided once the pipeline is triggered. It should be defined at a “pipeline” level and only
one directive is allowed for the whole pipeline.
─ We can use multiple parameters like,
─ Boolean parameter
─ String parameter
─ Choice parameter
─ File parameter
─ Password parameter
─ Run parameter
─ Multiline string parameter

33 © Atos|Syntel - For internal use


Declarative Pipeline
─ Post:
─ Post sections can be added at a pipeline level or on each stage block and sentences included in it are executed once
the stage or pipeline completes.
─ Several post-conditions can be used to control whether the post executes or not:
─ always: Steps are executed regardless of the completion status.
─ changed: Executes only if the completion results in a different status than the previous run.
─ fixed: Executes only if the completion is successful and the previous run failed
─ aborted: Steps are executed only if the pipeline or stage is aborted.
─ failure: Steps are executed only if the pipeline or stage fails.
─ success: Steps are executed only if the pipeline or stage succeeds.
─ unstable: Steps are executed only if the pipeline or stage is unstable.
─ regression: Executes only if current execution fails, aborts or is unstable and the previous run was successful.

34 © Atos|Syntel - For internal use


Declarative Pipeline
Ex:
pipeline {
agent any
stages {
stage('Some steps') {
steps {
...
}
}
}
post {
always {
echo “Pipeline finished”
bat ./performCleanUp.bat
}
}
}

35 © Atos|Syntel - For internal use


Declarative Pipeline
─ Script
─ This step is used to add Scripted Pipeline sentences into a Declarative one, thus providing even more functionality.
This step must be included at "stage" level.
─ Several times blocks of scripts can be utilized on different projects. These blocks allow you to extend Jenkins
functionalities and can be implemented as shared libraries.

36 © Atos|Syntel - For internal use


Declarative Pipeline
Ex:
pipeline {
agent any
stages {
stage('Sample') {
steps {
echo "Scripted block"
script {

}
}}
}
}

37 © Atos|Syntel - For internal use


Declarative Pipeline
─ Tools:
─ The “tools” directive can be added either at a pipeline level or at the stage one. It allows you to specify which
maven, jdk or gradle version to use on your script.
─ Any of these tools, the three supported at the time of writing, must be configured on the “Global tool
configuration”
Ex:
pipeline {
agent any
tools {
maven 'apache-maven-3.0.1'
}
stages {
...
}
}

38 © Atos|Syntel - For internal use


Declarative Pipeline

Pipeline Start of the pipeline script


Agent any It defines number of nodes currently we’re having master node only
so we can mention Agent any.

Environment We can integrate Jenkins with multiple environments; hence we


mention it for sonar. (It may not require every time)
Tools It defines the number of tools name and path, integrated with
Jenkins

Stages It will enable number of stages in our pipeline


Stage You can name your stages here

Steps Here you can add required configurations and commands.

39 © Atos|Syntel - For internal use


Scripted Pipeline
─ Jenkins pipelines are traditionally written as scripted pipelines.
─ Ideally, the scripted pipeline is stored in Jenkins webUI as a Jenkins file. The end-to-end scripted pipeline script is written
in Groovy.
─ It requires knowledge of Groovy programming as a prerequisite.
─ Jenkinsfile starts with the word node.
─ Can contain standard programming constructs like if-else block, try-catch block, etc.
─ Ex:
node {
stage('Stage 1') {
echo 'hello'
}
}

40 © Atos|Syntel - For internal use


Create pipeline project
 Click New item  Provide name of your project
 Choose Pipeline and continue.

41 © Atos|Syntel - For internal use


Pipeline

42 © Atos|Syntel - For internal use


Declarative Pipeline
 Go to pipeline section under Job configuration and type your pipeline script

43 © Atos|Syntel - For internal use


Declarative Pipeline
 Click Apply and save.
 You can click Build now to run the pipeline.
 Now you can able to see stage view like this, if no errors.

44 © Atos|Syntel - For internal use


Thank you

You might also like