Table of contents
No headings in the article.
Hey there, fellow tech enthusiasts! Today, we're delving into the fascinating world of Jenkins Declarative Pipeline โ a pivotal aspect of your DevOps and CI/CD journey. Let's dive in!
Understanding the Basics:
Before we get started, let's brush up on some key terms:
๐ข๏ธ Pipeline: Think of it as a roadmap for your software development lifecycle. A pipeline comprises a series of interconnected steps or jobs.
๐ฌ Declarative: This is the newer, more sophisticated implementation of a pipeline as code in Jenkins. It emphasizes simplicity and readability.
๐ป Scripted: This was Jenkins' initial approach to pipeline as code. It's built with Groovy and serves as a versatile DSL.
Why You Need a Pipeline:
Having a Jenkins Pipeline is like having a well-oiled machine for your software delivery process. Here's why it's indispensable:
๐ Version Control: By defining your pipeline in a Jenkins file and storing it in your project's source control repository, you're treating your CD pipeline as a crucial part of your application code. This means it's versioned and reviewed just like any other code.
๐ Automation: With a Jenkins Pipeline, you automate the build, test, and deployment processes, streamlining your entire workflow.
Understanding Pipeline Syntax:
Let's take a look at a basic structure of a Jenkins Declarative Pipeline:
pipeline { agent any stages { stage('Build') { steps { // Your build steps here } } stage('Test') { steps { // Your test steps here } } stage('Deploy') { steps { // Your deployment steps here } } } }
Task-01: Getting Started
Now, let's roll up our sleeves and dive into our first task:
๐ง Step 1: Create a New Job
Head over to your Jenkins dashboard and create a new job. This time, opt for "Pipeline" instead of "Freestyle Project." This sets the stage for a more structured, streamlined approach to your pipeline.
๐ Step 2: Follow the Official Jenkins Hello World Example
The official Jenkins documentation provides an excellent "Hello World" example to get you started. It's a fantastic way to familiarize yourself with the basics of a Declarative Pipeline.
Navigate to the project configuration page and proceed to the pipeline section.
Choose "Pipeline script" as the definition and input the script as follows:
For Declarative Pipeline: Begin with the mandatory 'pipeline' block. Agent: Specifies where the Jenkins build job should run. In this case, we've set it to 'any.'
Stages: Contains multiple executable 'stage' blocks. At least one 'stage' block is necessary within the 'stages' block. Here, we've named it 'Hello.'
Steps: Includes the actual operations performed within Jenkins. In the provided example, we're printing 'Hello World.' To initiate a manual build, click on the 'Build Now' link on the project's main page. After the build completes, access the console output by clicking on the "Console Output" link in the build page.
๐ก Step 3: Complete the Example using Declarative Pipeline
Now, let's delve further.
Create a Jenkinsfile in the todo-app node.js project with pipeline syntax and store it in the repository.
In the Jenkinsfile, also include Docker-compose.yaml.
We'll construct a pipeline for the repository using the Jenkinsfile and Docker-compose file as outlined below.
Configure the following steps as crucial stages for building the pipeline.
Execute the pipeline to monitor for errors or successful completion.
View the console output to track progress.
Navigate to the deployment using the public IP address followed by port 8080.
By embracing Jenkins Declarative Pipeline, you're not just automating your processes โ you're paving the way for smoother, more efficient software delivery.
Stay tuned for more insights on our DevOps journey! Until next time, happy coding! ๐โจ You can connect with me at: https://www.linkedin.com/in/davendersingh/