Table of contents
What is a Pipeline
A pipeline is a collection of steps or jobs interlinked in a sequence.
Declarative: Declarative is a more recent and advanced implementation of a pipeline as a code.
Scripted: Scripted was the first and most traditional implementation of the pipeline as a code in Jenkins. It was designed as a general-purpose DSL (Domain Specific Language) built with Groovy.
Why You Should Have a Pipeline?
The definition of a Jenkins Pipeline is written into a text file (called a Jenkinsfile) which in turn can be committed to a project’s source control repository.
This is the foundation of "Pipeline-as-code"; treating the CD pipeline as a part of the application to be versioned and reviewed like any other code.
It is a combination of plugins that support the integration and implementation of continuous delivery pipelines using Jenkins. In Jenkins, a pipeline is a collection of events or jobs that are interlinked with one another in a sequence.
In other words, a 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. It is used to incorporate continuous delivery in our software development workflow.
Creating a Jenkinsfile and committing it to source control provides several immediate benefits:
Automatically creates a Pipeline build process for all branches and pull requests.
Code review/iteration on the Pipeline (along with the remaining source code).
Pipeline syntax
pipeline {
agent any
stages {
stage('Build') {
steps {
//
}
}
stage('Test') {
steps {
//
}
}
stage('Deploy') {
steps {
//
}
}
}
}
Task
Create a New Job, this time select Pipeline instead of Freestyle Project and Complete a simple example using the Declarative pipeline
Create an EC2 instance and install Jenkins on it. Access Jenkins using the public IP of the instance on port 8080.
Once the Jenkins installation is complete we will be able to access the same on the browser, then open the Jenkins Dashboard and select “New Item”.
After clicking on OK we will get the “Project Configuration” section. There go to the “pipeline” section and select “Pipeline script” in definition.
Write a basic Pipeline Script of “Hello world”. Click on the save button to save the Pipeline.
We can start the build process by clicking on the Build Now tab.
After the build is complete we can check the output of the build by clicking on the “Console Output”.
The build was successful and it has printed “Hello World”.