Day 26 Task: Jenkins Declarative Pipeline

Day 26 Task: Jenkins Declarative Pipeline

One of the most important parts of our DevOps and CICD journey is a Declarative Pipeline Syntax of Jenkins.

Here Some terms for your Knowledge

What is Pipeline?

Pipeline in DevOps is a continuous delivery process that involves building, testing, and deploying software applications in an automated manner. A pipeline consists of a set of stages, each of which represents a particular phase in the software delivery process, such as building the application, running unit tests, and deploying to production.

Pipelines are often defined using a domain-specific language (DSL) that allows developers to specify the different stages and actions that should be taken during each stage. By automating the entire software delivery process, pipelines can help teams reduce errors, improve speed and efficiency, and ensure that software is delivered consistently and reliably.

What is Declarative pipeline..?

Declarative pipeline is a concept in Jenkins Pipeline, which is a plugin that enables continuous delivery and integration pipelines to be built into Jenkins. The declarative pipeline syntax provides an easy and intuitive way to define your build, test, and deployment stages as code.

With declarative pipelines, developers can easily create, maintain, and visualize the entire pipeline from code to deployment, allowing for more efficient and transparent collaboration between development and operations teams. The declarative pipeline provides a simplified and structured syntax for defining the pipeline, allowing developers to focus on the logic and flow of their pipeline rather than the underlying syntax.

What is Scripted Pipeline..?

In Jenkins, Scripted Pipeline is a more flexible and powerful way of creating Jenkins Pipelines as it allows users to write Pipeline code in Groovy, a scripting language for the Java platform. Scripted Pipeline provides a huge amount of control and extensibility and allows users to write scripts that can do almost anything that they can imagine.

It also allows users to define their own functions, reuse existing code, and make use of Jenkins-specific API functions to customize the behavior of the Pipeline. However, it requires more knowledge and experience in Groovy scripting compared to Declarative Pipeline, which can be easier to learn and use for beginners.

Why you should have a Pipeline..?

Having a pipeline in your software development process brings a number of benefits. First and foremost, it provides a structured and automated way to build, test, and deploy your software, making the process more efficient, consistent, and reliable. With a pipeline, you can catch and address errors early in the development cycle, reducing the likelihood of bugs and defects in your software.

Additionally, a pipeline allows for better collaboration and communication among team members, as everyone can see the status of the build and deployment process in real-time. Finally, having a pipeline can increase the speed of delivering new features and updates to your customers, enabling you to stay competitive in the fast-paced world of software development.

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 a number of 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 {
                      // 
                  }
              }
          }
      }