I’ll first get a simple example from day to day life. What is a pipeline? Here is an image of a pipeline

Pipeline

Here you can see sections in the pipeline. Think these each part has different processes. This is the concept that I want to highlight. Like this, Jenkins build process there can be few steps to go from development to production journey. When we get all these steps together, we call it a pipeline. Look at the following image,

There are five steps in the above pipeline.

  1. Commit — Checkout code from GIT, SVN, etc.. servers
  2. Build — Build the code using encryption algorithms(if any) or using build automation tools in this stage.
  3. Test — Use this stage to run tests such as Unit Tests, Integration Tests, and other code quality tests.
  4. Stage — Browser testing can be done using tools like Selenium, Mocha, etc.
  5. Deploy to QA or Development Testing — Code will be deployed to the staging server for testing.

These are the steps of Development to Production according to this pipeline.

How to create a pipeline in Jenkins

Log into Jenkins, then click New Item in the left panel. Enter a name for the pipeline, consider not to give a name with spaces in the middle. Using Camel Case is better. Then select Pipeline from selections and click OK. [Figure1.0]

Figure 1.0

Then you are redirected to the configuration screen of your created pipeline project. Then go to the pipeline section, select the definition as Pipeline script The important thing, give your Jenkins file name to Script Path. Select your SCM. [figure1.1]

 Figure 1.1

Your Jenkins File should store under your project and give that path to this text box. Your Jenkins file will be like the following which has been written in groovy. For more: https://www.jenkins.io/doc/book/pipeline/jenkinsfile/

pipeline {

agent any // indicates that Jenkins should allocate an executor and workspace for this part of the Pipeline

stages { //

stage(‘Build’) { // describes a stage of this Pipeline.

steps { // describes the steps to be run in this stage

sh ‘make’

}

}

stage(‘Test’){

steps {

sh ‘make check’ //executes the given shell command

junit ‘reports/**/*.xml’ // use to make test reports

}

}

stage(‘Deploy’) {

steps {

sh ‘make publish’

}

}

}

}

JUnit is used to create rest reports when running the build such as PHPUnit and codeception(for PHP). Like this, you can put your stages and steps according to your need when creating a build. After setting up the configurations correctly you click Apply and Save.

How is the process going on?

First Jenkins gets the clone or checkout whatever from the given repository URL and then goes through the stages. In each stage, it does what is about to do which has been given under stages of Jenkinsfile. So you can give your own steps through the process to make a build.

Advantages of a Jenkins Pipeline

Developers should not worry about Jenkin’s internal knowledge. The knowledge about how to make a pipeline should be enough in most cases. This is free of cost and portable to all the major platforms.

Try to use Jenkins pipeline for your software build processes.

Author: Viraj Amarasinghe – Senior Software Engineer at CMS.

Author : Administrator
Published Date September 29, 2020
Share Post