Day 26 Task: Jenkins Declarative Pipeline
One of the most important parts of DevOps and CICD journey is a Declarative Pipeline Syntax of Jenkins
Table of contents
Pipeline: A pipeline is a collection of steps or jobs interlinked in a sequence. It's used in Jenkins to define and automate the building, testing, and deployment of software applications or any other processes. Pipelines can be created using different approaches, such as declarative and scripted.
Declarative: Declarative is a more recent and advanced implementation of a pipeline as code in Jenkins. It provides a simplified and structured way to define pipelines using a DSL (Domain Specific Language). Declarative pipelines are easier to read and maintain and are suited for most use cases.
Scripted: Scripted was the first and most traditional implementation of the pipeline as code in Jenkins. It was designed as a general-purpose DSL built with Groovy. Scripted pipelines offer more flexibility and control compared to declarative pipelines but are often more complex to write and maintain.
These terms are essential for understanding how Jenkins pipelines work and the different approaches you can take when defining and managing them.
๐ถ Task-01: Create a Jenkins Declarative Pipeline
Create a New Job, this time select Pipeline instead of Freestyle Project.
1. Set Up Jenkins:
Install and configure Jenkins on your server or cloud platform.
sudo systemctl start jenkins sudo systemctl status jenkins
2. Create a New Item:
Go to your Jenkins dashboard and click on "New Item."
-
Enter a name for your project, select "Pipeline," and click "OK."
3. Configure Pipeline:
In the project configuration, scroll down to the "Pipeline" section.
Select "Pipeline script" from the "Definition" dropdown.
4. Write Declarative Pipeline Script:
In the script area, write your Declarative Pipeline script.
Here's an example of a HelloWorld application:
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building HelloWorld application...'
}
}
stage('Test') {
steps {
echo 'Testing HelloWorld application...'
}
}
stage('Deploy') {
steps {
echo 'Deploying HelloWorld application...'
}
}
}
}
5. Save and Run:
Click "Save" to save your pipeline configuration.
Click "Build Now" to run the pipeline.
6. Monitor Pipeline:
Monitor the progress of your Declarative Pipeline on the Jenkins dashboard.
Click on the pipeline run to view logs and details.
This example creates a simple Declarative Pipeline job that builds, tests, and deploys a HelloWorld application. Declarative Pipelines provide a structured and easy-to-read way to define your CI/CD processes in Jenkins.
Follow the Official Jenkins Hello World example.
Happy Learning :)
If you find my blog valuable, I invite you to like, share, and join the discussion. Your feedback is immensely cherished as it fuels continuous improvement. Let's embark on this transformative DevOps adventure together! ๐ #devops #90daysofdevop #git&github #jenkins