JenKins: Way to DevOps

Before going directly to Jenkins, let us try to understand what is DevOps....... As per my understanding DevOps is nothing but an day to day pratice which is used to address the gap between Developers and Operations i.e. DevOps makes Developers and Operations to work in tightly coupled development as well as production envrioment.

 

DevOps= Developer + Operational 

DevOps= Development Environment + Production Environment

 

Thus, from the above disucssion, it is very much clear that DevOps practice leads to Continuous Integration + Delivery + Deployment.

 

 

 

 

 But do you think, the above definition is sufficient to understand the DevOps......i think NO, DevOps is not only limited to Continuous Integration, Continuous Delivery, Continuous Deployment, extening to this DevOps in depth, it includes various phases which includes, PLAN -- CODE -- BUILD -- TEST -- INTEGRATE -- DEPLOY -- OPERATE -- MONITOR.   

                

 

                    

 

According to DevOps pratices, the workflow in software development and delivery is divided into above mentioned 8 phases ( Starts from Plan to Test and then Integrate to Monitor).

 

Developer one who practices above 8 phases continuously in their day to day activtiy, leads to Continuous Integration + Continuous Delivery + Continuous Deplpoyment, which nothing but DevOps practice.

 

 

Now after understanding, that how DevOps works and how it can leads any software product to continuous deployment to the production enviroment, now let us understand to how to achieve the DevOps Practice.

 

 

Towards implementation of DevOps (JENKINS)

 

Jenkins is nothing but free and open source automation server,it automates almost every part of SDLC (Software Development Life Cycle) which mainly includes Develop, Build, Test, Deploy, with providing the functionality of Continuous Integration, Continuous Delivery, Continuous Deployment.

 

Let us try to understand how Jenkins Pipeline works...........

 

Basically, Jenkins works in pipeline manner, in abstract way we can say that Jenkins Pipeline is a suite of Jenkins Features, installed as plugins, which helps us to enable implementation and integration of     continuous delivery pipeline into Jenkins.

 

 

 

In the above figure we can see that, Development and Prodution both are connected with the continuous pipeline of Code Commit, Build, Test, Release, Deliver/Deploy. 

 

Developer starts with thier respective code(s) whether they are code fixes (bug fixes) or they are new module enhancement, once developer done with thier code, they will first commit it, then they will run the build (here the main point that should be notes is Maven---mostly used as build tool, provides continuous build(s), for andriod Gradle is mostly used build tool), once the build is successfull, developer will test thier changes or developed code in the stagging or testing environment, after testing the code, code will be directly released to the production or operational environment by eleminating the manual QA process and from the production environment, code will be deployed or delivered as per the requirement(s).

 

Lets us try to understand the Jenkins working at the architecture level, below architecture diagram will help us to understand the same:

 

Jenkins Architecture...............

 

 

As we can see clearly in the architecture, that Jenkins architecture starts with bunch of developers and follows Jenkins Pipeline (discussed above) and ends with release to the production server with continuous integrations from all the developers to central code repository.

 

Thus we can conclude that Jenkins starts from Devlopers leading to CI---CD---CD and ends to Operatioals (Production) which is nothing but DevOps.

 

 

Required/Available Plugins for various services in Jenkins.....

 

In addition to CI/CD, jenkins provides various plugins to provide extra services like Docker (Container), AWS, Maven, GitHub, MS Build etc.

 

Developers in DevOps practice, commonly uses Docker (Container) to give an isolation or independency to an particular module or application during the development phase. Besides,Docker, Maven is mostly used plugins by developers during DevOps practice, to provide continuous Build process.

 

 

 

Types of Jenkins Pipeline

 

Before going to types of Jenkins Pipeline, we all must aware of 2 important technical terminologies:

 

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.



Also, a pipeline block is a key part of Declarative Pipeline syntax

 

 

Node.....A node is a machine which is part of the Jenkins environment and is capable of executing a Pipeline.

Also, a node block is a key part of Scripted Pipeline syntax.

 

Stage.......A stage block defines a conceptually distinct 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 single task. Fundamentally, 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,that typically means the plugin has implemented a new step.

 

Declarative Pipeline fundamentals................

 

In Declarative Pipeline syntax, the pipeline block defines all the work done throughout your entire Pipeline.



Jenkinsfile (Declarative Pipeline)

pipeline {

    agent any 1

    stages {

        stage('Build') { 2

            steps {

                // 3

            }

        }

        stage('Test') { 4

            steps {

                // 5

            }

        }

        stage('Deploy') { 6

            steps {

                // 7

            }

        }

    }

}

1: Execute this Pipeline or any of its stages, on any available agent.



2: Defines the "Build" stage.

3: Perform some steps related to the "Build" stage.

4: Defines the "Test" stage.

5: Perform some steps related to the "Test" stage.

6: Defines the "Deploy" stage.

7: Perform some steps related to the "Deploy" stage.



Scripted Pipeline fundamentals...................

 

In Scripted Pipeline syntax, one or more node blocks do the core work throughout the entire Pipeline. Although this is not a mandatory requirement of Scripted Pipeline syntax, confining your Pipeline’s work inside of a node block does two things:

  1. Schedules the steps contained within the block to run by adding an item to the Jenkins queue. As soon as an executor is free on a node, the steps will run.
  2. Creates a workspace (a directory specific to that particular Pipeline) where work can be done on files checked out from source control.
    Caution: Depending on your Jenkins configuration, some workspaces may not get automatically cleaned up after a period of inactivity. See tickets and discussion linked from JENKINS-2111 for more information.

Jenkinsfile (Scripted Pipeline)

node {  1

    stage('Build') { 2

        // 3

    }

    stage('Test') { 4

        // 5

    }

    stage('Deploy') { 6

        // 7

    }

}

 

1: Execute this Pipeline or any of its stages, on any available agent.

2: Defines the "Build" stage. stage blocks are optional in Scripted Pipeline syntax. However, implementing stage blocks in a Scripted Pipeline provides clearer visualization of each `stage’s subset of tasks/steps in the Jenkins UI.

3: Performs some stage related to the build stage.

4: Define the Test stage.

5: Performs some stage related to Test stage.

6: Defines Deploy stage.

7: Performs some stage related to Deploy stage.

 

Pipeline example......................

 

Jenkinsfile (Declarative Pipeline)

pipeline { 1

    agent any 2

    options {

        skipStagesAfterUnstable()

    }

    stages {

        stage('Build') { 3

            steps { 4

                sh 'make' 5

            }

        }

        stage('Test'){

            steps {

                sh 'make check'

                junit 'reports/**/*.xml' 6

            }

        }

        stage('Deploy') {

            steps {

                sh 'make publish'

            }

        }

    }

}

 

Above example describes an Declarative pipeline, in general practice Declarative pipeline is the most widely used pipeline due to:

1: Provides PAAC (Pipeline As A Code).

2: Resume from failed stage option available.

3: Easy to use advanced options.

4: Restart/Resume any stage.

 

 

----------------------------------------------------------------------------------------------------------------------------------------------------

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

    

 


Comments