Jenkins Pipeline
We can create a one click CI/CD deployment using pipeline, a pipeline is a collection of events or jobs which are interlinked with one another in a sequence. Integration and implementation of continuous delivery pipelines using Jenkins are supported by combination of plug-in.
What is a Continuous Delivery Pipeline?
Continuous delivery pipeline in Jenkins is represented by above diagram. It contains a collection of states such as commit, build, deploy an test. These jobs or events are linked with each other internally. Continuous delivery pipeline is sequence of jobs of every state.
Pipeline syntax
Two types of Pipeline syntax are generally required for defining and describing your JenkinsFile.
- Declarative: Pipelines are created using a simple way provided by Declarative pipeline syntax. It consists of a predefined hierarchy to create Jenkins pipelines.
- Scripted: Scripted Jenkins pipeline syntax runs on the Jenkins master with the help of a lightweight executor.
Why Should We Use the Jenkins Pipeline?
Reasons for using the Jenkins pipeline:
- Jenkins pipeline provide facility to resume pipeline automatically in case server undergoes an unpredicted restart.
- Jenkins pipeline is implemented as a code which allows several users to edit and execute the pipeline process.
- Jenkins Pipelines support big projects. You can run many jobs, and even use pipelines in a loop.
- You can pause the pipeline process and make it wait to continue until there is an input from the user.
Pipeline Concepts
- Pipeline: It is block defined by user which constitutes processes like build, test, deploy, etc. which combines all stages defined in a Jenkins File.
- Node: A machine on which Jenkins process runs is known as node. Pipeline syntax script uses node block.
- Stage: Stage is a block for steps of a pipeline i.e. build, test and deploy to process together in sequence in stage. Jenkins pipeline process is visualized by a stage block.
- Step: A step is a single task that executes a specific process at a defined time. A pipeline involves a series of steps defined within a stage block.
pipeline{ }
node{ }
Here is an example for multiple stages, where each stage performs a specific task:
pipeline { agent any stages { stage ('Build') { ... } stage ('Test') { ... } stage ('QA') { ... } stage ('Deploy') { ... } stage ('Monitor') { ... } } }
pipeline { agent any stages { stage ('Build') { steps { echo 'Running build phase...' } } } }