Introduction:
What is a Pipeline?
A pipeline is a collection of steps or jobs interlinked in a sequence. It is a suite of plugins that supports implementing and integrating continuous delivery pipelines into Jenkins.
A continuous delivery pipeline is an automated expression of your process for getting software from version control right through to your users and customers.
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.
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.
many features of 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 [1] and multiple options for integration with other plugins.
Pipeline syntax:
pipeline { agent any stages { stage('Build') { steps { // } } stage('Test') { steps { // } } stage('Deploy') { steps { // } } } }
Task-01: Create a Hello_World job using the declarative pipeline.
Create a New Job, this time select to follow the Official Jenkins Hello World example
Complete the example using the Declarative pipeline
Step 1: Launch an Ec2 Instance, and install JAVA, and JENKINS on the Jenkins-Server.Open a web browser and navigate to the Jenkins home page.
Login into the Jenkins dashboard and click on New Item.
Click on Save to create it.
Step 2: Add a valid description for the project.
Write script for pipeline(Groovy syntax).
Step 4: Click on Save and Then Build Now
Step 5: Check the Full Stage View for Execution Time
Once the pipeline execution starts, we can see the Full Stage View to see the different stages of our pipeline and the time it takes for each stage to complete.
Step 6: Observe console output.
Thank you for reading.
Happy Learning!!!!!!!!