Jenkins Pipeline

HOME

What is a Jenkins Pipeline?

Jenkins Pipeline (or simply “Pipeline”) is a suite of plugins that supports implementing and integrating continuous delivery pipelines into Jenkins.

Jenkins Pipeline provides an extensible set of tools for modeling simple-to-complex delivery pipelines “as code”. The definition of a Jenkins Pipeline is typically written into a text file (called a Jenkinsfile) which in turn is checked into a project’s source control repository.

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).
  • Audit trail for the Pipeline.
  • Single source of truth for the Pipeline, which can be viewed and edited by multiple members of the project.

Why do we need Jenkins pipeline?

  1. 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.
  2. Durable: Pipelines can survive both planned and unplanned restarts of the Jenkins controller.
  3. Pausable: Pipelines can optionally stop and wait for human input or approval before continuing the Pipeline run.
  4. Versatile: Pipelines support complex real-world CD requirements, including the ability to fork/join, loop, and perform work in parallel.
  5. Extensible: The Pipeline plugin supports custom extensions to its DSL and multiple options for integration with other plugins.

Jenkins Pipeline Concepts

Pipeline A Pipeline is a user-defined model of a CD pipeline. A Pipeline’s code defines your entire build process, which typically includes stages for building an application, testing it, and then delivering it.
Node A node is a machine that is part of the Jenkins environment and is capable of executing a Pipeline.
Stage stage block defines a subset of tasks performed through the entire Pipeline (e.g. “Build”, “Test” and “Deploy” stages), which is used by many plugins to visualize or present Jenkins Pipeline status/progress.
Step A step tells Jenkins what to do at a particular point in time (or “step” in the process). For example, to execute the shell command make use the sh step: sh 'make'. When a plugin extends the Pipeline DSL, [1] that typically means the plugin has implemented a new step.

Jenkins supports two different syntaxes.

  1. Declarative
  2. Scripted

Declarative

Declarative pipeline syntax simplifies pipeline construction. It comes with a predefined hierarchy for creating Jenkins pipelines. It gives you simple and straightforward control over all aspects of pipeline execution.

Scripted

A lightweight executor is used to run a scripted Jenkins pipeline on the Jenkins master. It uses minimal resources to convert the pipeline into atomic commands. Declarative and scripted syntax are distinct and are defined in entirely different ways.

The following example shows a Declarative pipeline with 2 stages:

pipeline {
    agent any 

    stages {
        stage('Build ') {
            steps {
                echo 'Building the project...'
            }
        }

        stage('Test') {
            steps {
                echo 'Testing the project...'
            }
        }
    }
}

We have got some ideas about Jenkins Pipeline.

Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!! Cheers!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s