DEV Community

Cover image for Introduction to Jenkins Pipeline
Rohith ND
Rohith ND

Posted on • Updated on

Introduction to Jenkins Pipeline

Jenkins Pipeline is a collection of plugins that aid in the implementation and integration of continuous delivery pipelines into Jenkins.Pipeline offers an extendable collection of tools for modelling basic to complex delivery pipelines "as code" using the Pipeline Domain Specific Language (DSL).

A pipeline's purpose is to allow builds to flow through it constantly, similar to how water flows through a plumbing system; fluid and always available. The goal is to deploy and/or release the modifications contained in the builds into production.

A continuous delivery pipeline is an automated representation of your software delivery process, from version control to your users and clients. Every update to your program (committed in source control) through a rigorous procedure before it is released. This process involves constructing the software in a dependable and repeatable manner, as well as advancing the developed software (referred to as a "build") through various phases of testing and deployment.

The specification of a Jenkins Pipeline is often written into a text file (known as a Jenkinsfile), which is then checked into a project's source control repository. Creating a Jenkinsfile has a lot of obvious advantages:

  • Create Pipelines automatically for all Branches and Pull Requests
  • Code review/iteration on the Pipeline
  • Audit trail for the Pipeline
  • Single source of truth for the Pipeline that can be seen and changed by different project members
// Declarative //
pipeline {
    agent any 
    stages {
        stage('Build') { 
            steps { 
                sh 'make' 
            }
    }
    stage('Test'){
        steps {
            sh 'make check'
            junit 'reports/**/*.xml' 
        }
    }
    stage('Deploy') {
        steps {
            sh 'make publish'
        }
    }
}
}
Enter fullscreen mode Exit fullscreen mode
  • ① Jenkins should allocate an executor and workspace for this segment of the Pipeline, as indicated by the agent.
  • ② This Pipeline's stage is described by stage.
  • ③ steps summarises the steps that will be performed at this stage
  • ④ sh executes the given shell command
  • ⑤ The plugin provides junit as a Pipeline step: junit is a JUnit plugin for collecting test results.
//sample
node {
    stage('Build') {
        sh 'make'
    }
    stage('Test') {
        sh 'make check'
        junit 'reports/**/*.xml'
    }
    stage('Deploy') {
        sh 'make publish'
    }
}
Enter fullscreen mode Exit fullscreen mode

Reference : Jenkins User Handbook , Mastering Jenkins

Top comments (0)