Release Management Explained: Dev To Prod Deployment Process

Release Management Process explained

If you are into DevOps it is very important to understand release management. There is no single template for release management. It can differ from organization to organization.

In this article, I will explain what release management is and one of the processes we adopted for our implementations.

What is Release Management?


Release management is a structured model. Planning, scheduling, and controlling the project in each stage or environment with testing and deployments.

It makes application deployments as a stable and smooth one. It avoids half-baked releases by constantly following a process and approval mechanism.

Release management is required for the new project or even changes to an existing project. It prevents deployment delays and last-minute issues as it goes by a well-defined process.

With paradigms like DevOps, we can achieve a smooth transition of application from one state to another with collaboration, automation, and well-defined feedback loops.

Release Process Components

  1. Release Model: A specific release process from project planning to delivery.
  2. Release Policy: The definition of release standards, types and requirements to set the release process
  3. Release Template: A single and repeatable workflow to release process that includes human and automated activities. In other words, a release management checklist.
  4. Release Plan: Activities involved deploying a release to production
  5. Major Release: Include many release units that have a higher and critical business impact
  6. Minor Release: Include fewer release units that do not include critical components

Release Models

Design the release model based on the customer’s requirements.

For example, In our previous releases, process checkpoints, validation, and verification were not seamless.

We customized the release model to overcome the issues. Below, given the comparison table for the previous vs current release process


Previous Model

Current Model
Branching Strategy: Developers working on the same branch (Sprint)There is no checkpoint to merge the code (Lagging Code Review)Automated jobs are trigger for each commitBranching Strategy:
Developers working on their feature branch Checkpoint to merge the feature branch to sprint branch (Via Pull request)Reviewer need to review the code and approve the pull request based on the build statusAutomated jobs are trigger based on the pull request (Create, Update and Merge)CI build status in Bitbucket
CI Test Classes are optional.
Lagging code coverage.
There is no custom script for deployment.
Maintaining the Build file manually
CI Test Classes are mandatory (Test classes in runtests.txt)
Better Code Coverage
A custom script for deployment (manifest.txt to generate package.xml)
Generate the build file automatically 

Release Branching Strategy


In version control systems, Branching is a technique that make a copy of source code. 

sprint wise branching strategy

In this Release model master contains the production copy. Create a develop copy from the master. Develop branch contains all the developed components.

In an Agile model, the stories are aligned as a sprint. So, create a sprint copy (feature branch) from the develop branch. Based on the stories the developer needs to create their own user story branch from sprint copy.

Once the developers complete their stories, they need to create a pull request from their story branch to sprint copy. The reviewer takes the responsibility to review and merge the code.

The develop branch contains all the completed sprint copies. Once we plan for a higher environment release need to create a release branch from the develop branch. Based on the project release we can also create a release copy from sprint itself.

future sprint wise branching strategy

Importance of Branching Strategy

  1. It provides better code management. We can track the changes by time, person, and versions.
  2. Developers can work on their stories independently by creating a separate story branch.
  3. Work between current and existing tracks easily because maintaining the code by versioning.
  4. collaborate better and spend less time managing version control and more time developing code.
  5. Merging will happen only via a pull request that gives a checkpoint to review the code.
  6. Proper branching will provide a smooth development and fast release.

Git-Hook

Once the developer cloned their branch into local, they need to install the git-hook(pre-commit) script. It is used to track the current committed components in a text file called manifest.txt. Also, it generated the runtests.txt file. In that developers need to maintain the related test classes to get the successful deployment.

pre commit git hook

Folder Structure:

release manifest file

Manifest:

  • Automatic change log
  • Key file for any build jobs, used to generate the package.xml
  • Can be modified manually if required

Runtest:

  • Developer must list down the test class
  • Key file for any build jobs, used to generate the ant build.xml file
  • Need at least one test to run the build

Release Management Process Overview


In this section, we will look at a release management example from source code to release phase.

Source Code Management (SCM):

Source control is the practice of tracking and managing changes to code. It provides a history of code development. Each version will be shown with the time and includes the person’s name when made the change.

Development phase:

The developer completes their ticket and creates a pull request from the user story branch to the sprint branch. Once they create a pull request, Jenkins Dev-Int validate job will get trigger automatically.

Dev-Int: Dev Integration sandbox that is used for unit testing

Reviewers will review the code and merges the pull request only when Dev-Int validate job gets success. Based on the job status the reviewer started to review the code and merge the user story copy into sprint copy.

At the time Dev-Int deploy job will get a trigger and the components present in the sprint branch will get deployed to Dev-Int sandbox. QA validate job will get triggered once Dev-Int is successfully deployed.

After the QA validation gets success, the QA team requests the DevOps team to deploy the sprint branch components to the QA sandbox. DevOps team will deploy and notify QA team about the success or failures. (This notification process can be automated)

After completion of each sprint that will be merged with the develop branch via pull requests. 

release management architecture

Release phase:

The successful completion of sprints will be merged into the develop branch. A release branch will be created from the develop branch when we need higher environment deployments.

Roles and Responsibilities:

Application release roles and responsibilities

Benefits

  1. Track the changes over source code using SCM.
  2. Help to find and fix the defects fast during the deployments.
  3. Test classes are mandatory to deploy the component from the lower environment onwards. So, developers can find test failures in the early stages.
  4. Increase the code coverage.
  5. DevOps takes the responsibility to do the manuals. Developers need to document the manuals in teamwork or confluence. So, it will reduce the chances of missing the pre/post manuals.
  6. Increase productivity.
  7. In CI server the DevInt deployment and QA validation are automated ones. It will reduce the overall deployment time.

Risks (If missed to follow)

  1. No tracking on changes
  2. Overwriting each other’s changes
  3. Risk of missing manual changes
  4. Less productivity
  5. More defect
  6. More rework

Release Management Tools

There are many tools enterprise tools available for release management.

However, some oraganizations will make use of their exitisng tools and open source tools for their release process.

Here are some popular tools in the release management segment.

  1. Spinnaker [Opensource Continuous Delivery Tool]
  2. Go CD [Open Source]
  3. XL release [Enterprise]
  4. Harness [Enterprise – For Container-Based application release]

Conclusion

Release management presents a tremendous opportunity to drive continuous improvement in software delivery throughout an enterprise.

It provides greater visibility and traceability throughout the release. This release process gives the efficiency of release planning, review the process to accelerate and improve software delivery.

Release Management Process explained

6 Top Project Management Software for 2020: Start For Free

Top Project management Softwares

In the corporate structure today, project management software is of utmost importance. It helps project managers and teams to meet various requirements.

With the paradigm of business constantly changing, a lot of medium, as well as small scale businesses, are now using the project management software.

Moreover, it is helping them to increase their productivity and work efficiency without having to exceed the budgetary limit. 

List of Best Project Management Software

As time passes by, the number of project management tools increases in the market. Each of its exciting features, it becomes very perplexing to choose the right one.

In this project management software list, we will look into the top 6 tools that can be used for personal project tracking to enterprise-level scrum-based project tracking.

Well, if you are planning on introducing a project management software to your business, you must have these on your watch list.

Backlog.com


Official Website: www.backlog.com


A great online project management tool that allows you to have total control over your project and monitor every aspect. With this software, you will be able to track the progress of your project effectively. Along with Gantt as well as burndown charts, you will be able to manage time and schedules efficiently. Plus, it also offers special task management features. It allows creating and updating different tasks while assigning sub-tasks and deadlines to them.

Features:

  1. It will enable you to create wikis with project details that your team members can download and familiarise with.
  2. It offers efficient centralized file sharing.
  3. Also, it makes it easy to communicate with specific members of the team.

Pricing: Backlog has a free plan that allows you to add 10 members and offers 100 MB of storage space. Other than that, it has three payable packages: Starter, Standard, and Premium. The pricing starts from $35/ month with the starter plan.

backlog best project management software

Jira


Official Website: www.atlassian.com


Jira is a multi-platform bug, as well as issue tracking software. It comes with efficient project management features. Next, the software allows you to distribute the tasks amongst your team and cater to different issues. Most importantly, it also enables you to fix bugs and track the progress with interactive charts and Kanban boards.

Features:

  1. Jira offers real-time reporting about the works of your members.
  2. It centralizes the communication of the entire team and brings efficiency.
  3. It provides roadmaps to present your plans to your stakeholders easily.

Pricing: Free plan for up to 10 users, and the Standard plan caters up to 5000 users for $7. However, the Premium plan offers 5000 users and 1000 executions per month for $14/month.

jira best project management software

Trello


Official Website: www.trello.com


A simple as well as user-friendly PM software, Trello mostly relies on Kanban boards to manage projects. It provides a special board for each task which every team member can access easily. Plus, these boards are customizable, and any member can customize them as they require. Also, it allows you to drag and drop tasks on the dashboard. Thus, it makes it very easy to manage the tasks, schedule them, and set their priorities. 

Features:

  1. It makes it easy to create and maintain an unlimited number of tasks.
  2. Indeed allows you to share images and files.
  3. Furthermore, it becomes easy to make internal comments and collaborate efficiently with the team. 

Pricing: Trello has a free plan that is perfect for small businesses and personal use. For a medium and large business, there are Business Class and Enterprise plans. The pricing starts with $9.99/ month. 

trello best project management software

Asana


Official Website: www.asana.com


Asana is a highly efficient project management software that runs on the cloud. It is highly adaptable and can quickly adapt to your working style. Moreover, it allows you to fix every detail of your business effectively. Also, it offers a personalized dashboard as well as a search option. Plus, it will enable you to group tasks in columns or sections or as boards. 

Features:

  1. It comes with a personalized inbox for communicating with other members.
  2. It certainly helps to generate in-detail project reports.
  3. It makes it easy to create a calendar to sort tasks as per priority. 

Pricing: It offers three different plans: Free, Premium, and Enterprise. The free plan is perfect for every business starting to use PM tools. The Premium plan starts from $9.99/ month.

asana best project management software

Monday.com


Official Website: www.monday.com


Monday project management is a simple yet effective online software. It allows you to meet deadlines, bring transparency to your processes, and manage the tasks. The tool makes it easy to control what others are working on, track progress, centralize the communication channels, and proper management of documents. 

Features:

  1. Monday.com offers proper analytics and real-time reporting.
  2. It allows you to collaborate with third-parties.
  3. Easily integrates with Google Drive, Dropbox, zapier, and other similar file-sharing tools.

Pricing: It offers a free trial. There are four plans: Basic, Standard, Pro, and Enterprise. The pricing starts $39/month with the Basic Plan. 

Monday.com - Top Project management tool

Clickup


Official Website: www.clickup.com


Focuses mostly on improving productivity, it allows you to manage tasks, time, and projects efficiently. It allows you to monitor every member and see what they are doing. Furthermore, it brings every task as well as a resource into a single place for better utilization.  

Features:

  1. It allows you to collaborate efficiently with all members and customize your workflow.
  2. You can also add the estimation of time for auto-scheduling.
  3. Also, you can create a task and control what your team members see or do. 

Pricing: Comes with a free plan with 100MB storage and unlimited tasks as well as users. You can also avail of the Unlimited plan for $5 or Business Plan for $9.

clickup top project tracking tool

Wrike


Official Website: www.wrike.com


Wrike is an all in one tool for all your project management activities. It is used by more than 20000 companies. You can organize all project tasks as a list or kanban board. If you run project scrums, you can use the relevant Wrike template to create respective project scrum boards and charts.

Features:

  1. Project templates for tasks list, kanban boards, etc.
  2. Project billing features
  3. Time and bug tracking.
  4. Third-party application integration (Single sign-on, CRM etc)
best project tracking tool wrike

What is the best project management software?

Before selecting any tool, you need to do your own research on existing tools that you are using in your organization.

For example, if you using Atlassian Bitbucket for source code management, it is better to go with Jira for project management as it will provide more integrations with Bitbucket.

Project management is not just listing down tasks or user stories in tools. First, you need to list your requirements.

Check the tool features that go with your requirement and integration with your existing tools. Whichever tool offers the best integration and support, go for it.

For personal projects and small teams, you can start with Backlog, Asana, or Trello. All these tools provide wonderful templates and workflows for tracking tasks.

If you are looking for an enterprise-grade solution, Jira will top it all. It has excellent integration with all the features you would be looking for.

Free Project Management Software

Well most of the softwares we listed in this article supports free users. If you have a very small team, you can start with free subscriptions

For example,

  1. Backlog & Jira offer a free subscription of up to 10 users.
  2. Asana supports up to 15 users.
  3. Trello supports 10 free team dashboards
  4. Clickup Supports unlimited tasks and users with 100 MB storage

How Project Management Software increases your productivity?

In a world where technology is growing rapidly, using project management software is crucial to ensure success for your business.

With project management software, you will be able to control the task and have everyone meet the deadlines. Plus, it will also become easy to fix the deadlines and cater to different constraints easily.

Moreover, the project management tools also come with inbuilt chatting and interaction features.

In other words, project management software combines all the parts of a business or a project in a single place. Thus, it allows you and your team to function better as a unit and meets the goals. 

So…What Do You Think?

Project Management tools are essential. It increases productivity and brings efficiency to your workflow. Have a look at the software above and choose the one that suits your needs best. 

Now we want to hear from you.

What do you think of this list?

Or maybe we missed one of your favorite project management tools.

Either way, let us know by leaving a comment below.

Top Project management Softwares

Kubernetes Tutorials For Beginners: Getting Started Guide

Kubernetes Tutorials For Beginners: Getting Started Guide

Official kubernetes (k8s) website says,

Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications. It groups containers that make up an application into logical units for easy management and discovery. Kubernetes builds upon 15 years of experience of running production workloads at Google, combined with best-of-breed ideas and practices from the community.

As the definition says, Kubernetes or k8s is an open-source orchestration and cluster management for container-based applications.

Why we need Kubernetes?

The first question when it comes to Kubernetes or a container orchestrator is that, why we need it. Let’s understand it from two examples.

Example 1: Container Deployments

Let’s say you have a couple of java application.

You can package it into a container and run it on a server containing docker. For this scenario, there is no complexity.

You just package your application into a Docker image using Dockerfile and expose a port on a host for the external world to access it.

The only downside is that it is a single point of failure as it is a single server. You need an efficient mechanism to handle a single point of failure.

This is why you need a container clustering & orchestration tool like Kubernetes to scale applications on-demand and to withstand single node failures.

Example 2: Microservices Deployment/Orchestration

Now, let’s say, you have a big application that is composed of microservices (APIs, UI, user management, credit card transaction system, etc).

All these microservice components have to talk to each other using REST or other protocols.

As the application has many components or microservices, we cannot pack all the services into one server or a container.

The application has to be decoupled and each microservice should be deployed and scaled on its own. This makes the application development and deployment easier and faster.

In this scenario, the complexity lies in networking, shared file system, load balancing, and service discovery.

Here is where kubernetes comes in to picture. It helps in orchestrating the complex processes in a manageable way.

Using kubernetes you just have to worry about your application development and deployments. All heavy lifting like networking, load balancing, resource scheduling, scalability, and high availability will be taken care of by kubernetes.

Kubernetes Tutorials For Beginners

We have listed down a list of tutorials that you can use to get started with kubernetes. This is a growing list.

Architecture & Setup:

  1. The Illustrated Children’s Guide to Kubernetes
  2. Kubernetes Architecture Explained
  3. Setup Kubernetes Cluster Using Kubeadm

Kubernetes Deployments:

  1. Kubernetes Deployment Tutorial For Beginners
  2. How To Create Kubernetes Service Account
  3. Kubernetes Ingress Tutorial For Beginners
  4. How To Set Up Ingress On Kubernetes Using Nginx Controller
  5. How To Create Kubernetes Jobs/Cron Jobs
  6. How To Setup Prometheus Monitoring On Kubernetes Cluster
  7. Setup Jenkins On Kubernetes Cluster 
  8. Setting Up Alert Manager On Kubernetes
  9. Setup Latest Nexus OSS On Kubernetes

Kubernetes Tools:

  1. How To Install And Configure Helm for Kubernetes Deployment

Kubernetes Certitification (CKA/CKAD):

  1. Kubernetes Certification Tips From A Kubernetes Certified Administrator
  2. Kubernetes Certification Coupon: 16% Off + $100 Off On Kubernetes Course Bundle

Related Online Courses:

  1. Kubernetes Tutorials From LinkedIn Learning [Check Free LinkedIn Learning Account]
  2. Getting Started with Kubernetes [Check Pluralsight Free Access]

Subscribe to our mailing list to keep updated on our latest Kubernetes tutorials.

Kubernetes Tutorials For Beginners: Getting Started Guide

Helm Tutorial: How To Install and Configure Helm

Helm Tutorial on installation

This post explains how to install helm 3 on kubernetes and configure components for managing and deploying applications on the Kubernetes cluster.

Prerequisites

You should have the following before getting started with the helm setup.

  1. A running Kubernetes cluster.
  2. The Kubernetes cluster API endpoint should be reachable from the machine you are running helm.
  3. Authenticate the cluster using kubectl and it should have cluster-admin permissions.

Helm 3 Architecture

In helm 3 there is no tiller component. Helm client directly interacts with the kubernetes API for the helm chart deployment.

install helm 3 without tiller

Helm 2 Architecture

In helm 2 there is a helm component called tiller which will be deployed in the kubernetes kube-system namespace. Tiller components is removed in helm 3 versions.

helm2 architecture min

Install Helm 3 Without Tiller

Note: The workstation you are running should have the kubectl context set to the cluster you want to manage with Helm.

Download the latest helm 3 installation script.

curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3

Add execute permissions to the downloaded script.

chmod 700 get_helm.sh

Execute the installation script.

./get_helm.sh

Validate helm installtion by executing the helm command.

helm

Now, add the public stable helm repo for installing the stable charts.

helm repo add stable https://kubernetes-charts.storage.googleapis.com/

Lets install a stable nginx chart and test the setup.

helm install nginx stable/nginx-ingress

List the installed helm chart

helm ls

Installing & Configuring Helm 2

This installation is on the client-side. ie, a personal workstation, a Linux VM, etc. You can install the helm using a single liner. It will automatically find your OS type and installs helm on it.

Execute the following from your command line.

curl -L https://git.io/get_helm.sh | bash

Create Tiller Service Account With Cluster Admin Permissions

Tiller is the server component for helm. Tiller will be present in the kubernetes cluster and the helm client talks to it for deploying applications using helm charts.

Helm will be managing your cluster resources. So we need to add necessary permissions to the tiller components which resides in the cluster kube-system namespace.

Here is what we will do,

  1. Create a service account names tiller
  2. Create a ClusterRoleBinding with cluster-admin permissions to the tiller service account.

We will add both service account and clusterRoleBinding in one yaml file.

Create a file named helm-rbac.yaml and copy the following contents to the file.

apiVersion: v1
kind: ServiceAccount
metadata:
  name: tiller
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: tiller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: tiller
    namespace: kube-system

Lets create these resources using kubectl

kubectl apply -f helm-rbac.yam

Initialize Helm: Deploy Tiller

Next step is to initialize helm. When you initialize helm, a deployment named tiller-deploy will be deployed in the kube-system namespace.

Initialize helm using the following command.

helm init --service-account=tiller --history-max 300

If you want a specific tiller version to be installed, you can specify the tiller image link in the init command using --tiller-image flag. You can find the all tiller docker images in public google GCR registry.

helm init --service-account=tiller --tiller-image=gcr.io/kubernetes-helm/tiller:v2.14.1   --history-max 300

If you dont mention “–service-account=tiller”, you will get the following error.

Error: no available release name found

You can check the tiller deployment in the kube-system namespace using kubectl.

kubectl get deployment tiller-deploy -n kube-system

Deploy a Sample App Using Helm

Now lets deploy a sample nginx ingress using helm.

Execute the following helm install command to deploy an nginx ingress in the kubernetes cluster. It will download the nginx-ingress helm chart from the public github helm chart repo.

helm install stable/nginx-ingress --name nginx-ingress

You can check the install helm chart using the following command.

helm ls

You can delete the sample deployment using delete command. For example,

helm delete nginx-ingress

Remove Helm (Tiller) From Kubernetes Cluster

If you want to remove the tiller installtion from the kubernetes cluster use the following command.

helm reset

For some reason, if it throws error, force remove it using the following command.

helm reset --force

Also you can use the kubectl command to remove it.

kubectl delete deployment tiller-deploy --namespace kube-system

In the next blog post, we will look in to chart development and best practices of HELM

Helm Tutorial on installation

Jenkins Pipeline Tutorial For Beginners

Jenkins Pipeline as Code Tutorial

Jenkins pipeline as code is a concept of defining Jenkins build pipeline in Jenkins DSL/Groovy format. This article covers the key concepts involved in writing Jenkins pipeline as code using declarative syntax.

Jenkins Pipeline Tutorial

In this Jenkins pipeline tutorial, we will look at the following

  1. Types of Jenkins Pipeline
  2. Pipeline as code basics
  3. Building a basic CI pipeline as code for java app.
  4. Building a job from pipeline code present in source code repo.
  5. Executing parallel stages in a pipeline
  6. Generating pipeline script & directives using Jenkins inbuilt generators.

Types of Jenkins Pipeline

There are two types of Jenkins pipeline code.

  1. Declarative Pipeline
  2. Scripted Pipeline

In this tutorial, we will focus only on the declarative syntax as it is an advanced version of the scripted pipeline with extensible features. Also, I recommend using the declarative pipeline approach for all your Jenkins use cases. There are a lot of features and benefits you will get from the declarative pipeline approach.

You can check out my article on Jenkins’s multibranch pipeline which uses declarative pipeline as code with Jenkinsfile approach.

Now let’s get started with the pipeline tutorial.

For better understanding, we will create a pipeline for the Java Spring Boot application build using the declarative pipeline as code.

Prerequisites

  1. Jenkins master (Check Jenkins installation steps)
  2. Jenkins slave node connected to the master (Check Jenkins slave setup guide)
  3. Access to Github.com from your Jenkins server. If you are trying out from your corporate Jenkins setup, you can use your organization’s private git repo.

Here us the pictorial representation of the simple build pipeline we are going to build.

jenkins pipeline as code architecture

Here is the pipeline code for the above workflow. Before setting up the pipeline we will understand what each block means.

Note: Do not worry about the DSL used in the pipeline code. Read the article fully to understand how to generate the DSLs in an easy way.


pipeline {

    agent {
        node {
            label 'SLAVE01'
        }
    }

    tools { 
        maven 'maven3' 
    }

    options {
        buildDiscarder logRotator( 
                    daysToKeepStr: '15', 
                    numToKeepStr: '10'
            )
    }

    environment {
        APP_NAME = "DCUBE_APP",
        APP_ENV  = "DEV"
    }

    stages {
        
        stage('Cleanup Workspace') {
            steps {
                cleanWs()
                sh """
                echo "Cleaned Up Workspace for ${APP_NAME}"
                """
            }
        }

        stage('Code Checkout') {
            steps {
                checkout([
                    $class: 'GitSCM', 
                    branches: [[name: '*/master']], 
                    userRemoteConfigs: [[url: 'https://github.com/spring-projects/spring-petclinic.git']]
                ])
            }
        }

        stage('Code Build') {
            steps {
                 sh 'mvn install -Dmaven.test.skip=true'
            }
        }

        stage('Priting All Global Variables') {
            steps {
                sh """
                env
                """
            }
        }

    }   
}

Now lets understand what each block means.

  1. The Pipeline Block: All your pipeline as code should be wrapped inside the pipeline block.
pipeline {

---<All Pipeline blocks go here>---

}
  1. Agent Block: In the agent block you have to mention the slave details where you want to run the pipeline job. It supports both static slaves and docker based dynamic slaves. Here we have mentioned label as “SLAVE01“. It is the name of a slave node.
    agent {
        node {
            label 'SLAVE01'
        }
    }
  1. Tools Block: Here you can refer to the tools you have configured in the Jenkins Global tool configuration. We have covered the tool configuration in the next section.
tools { 
        maven 'maven3' 
    }
  1. Options Block: It contains all the options required for the job. One example, we have given is “Build Discarder” to rotate the build logs.
options {
        buildDiscarder logRotator( 
                    daysToKeepStr: '15', 
                    numToKeepStr: '10'
            )
    }
  1. Environment Block: In this block, you can mention all the required variables for the job which has to be available in all the stages. You can define any number of variables like a key-value pair.
    environment {
        APP_NAME = "DCUBE_APP",
        APP_ENV  = "DEV"
    }
  1. Stages: Stages block contains multiple stages.
stages {

---<All Pipeline Stages Go Here>---

}
  1. Stage Block: A stage is a subset of stages. Each stage has a steps block.

  1. Steps Block: In each steps block you define a set of operations to perform. In the following example, we have shown a workplace cleanup step and echoing a variable we defined in the environment block. What you want to run inside each stage depends totally on your use case.
stage('Cleanup Workspace') {
            steps {
                cleanWs()
                sh """
                echo "Cleaned Up Workspace for ${APP_NAME}"
                """
            }
        }

Now that we have a basic understanding of a minimal pipeline as code, lets practically execute this pipeline on a Jenkins server with a slave node.

Configure Pipeline as Code Job In Jenkins

To execute the pipeline code we have in this article, we need to configure maven in global tool configuration.

Go to Manage Jenkins –> Global Tool Configuration –> Maven –> Maven Installation.

Add a maven configuration as shown below. We are using the tool name as maven3 in the pipeline, so that it refers to the maven under “Global Tool Configuration”.

jenkins maven tool

Note: We have selected “Install Automatically” option, which will download the selected version every time you execute the job.

Creating & Building a Jenkins Pipeline Job

Follow the steps given below to create and build our pipeline as code.

Step 1: Go to Jenkins home and select “New Item”

image 10

Step 2: Give a name, select “Pipeline” and click ok.

image 11

Step 3: Scroll down to the Pipeline section, copy the whole pipeline code in the script section and save it.

image 12

Step 4: Now, click “Build Now” and wait for the build to start.

image 13

While the job starts you can view each stage executing in stage view. Here is the screenshot of a successfully executed job. Also, you can the job logs by clicking the blue icon.

image 14

If you have the blue ocean plugin installed, you can have a very good UI to view your job status and logs as shown below. Use the “Open in Blue Ocean” from the left to open a job in the blue ocean view.

image 15

Executing Jenkins Pipeline From Github (Jenkinsfile)

In the last section, we used the pipeline script directly on Jenkins. In this section, we will look at how to execute a pipeline script available in an SCM system like Github.

Step 1: Create a Github repo with our pipeline code in a file named Jenkinsfile. Or you can use this Github repo for testing. https://github.com/devopscube/pipeline-as-code-demo

Step 2: Follow the same steps we used for creating a pipeline job. But instead of entering the code directly into the script block, select the “Pipeline script from SCM” option and fill in the details as shown below.

  1. Definition: Pipeline script from SCM
  2. Repository URL: https://github.com/devopscube/pipeline-as-code-demo
  3. Script Path: Jenkinsfile
image 16

Step 3: Save the configuration and run the build. You should see a successful build.

Executing Jenkins Pipeline Stages In Parallel

There are use cases where you have to execute different stages in parallel because each stage will be independent and does not depend on other steps. Also, running separate stages in parallel will reduce the build times as well.

You can achieve parallelism in Jenkins pipelines as code using the parallel block.

Here is an example stage that contains three parallel stages. It’s like you will have multiple stages inside a stage. You can test this by adding the following code to your existing pipeline.

stage('Environment Analysis') {

            parallel {

                stage('Priting All Global Variables') {
                    steps {
                        sh """
                        env
                        """
                    }
                }

                stage('Execute Shell') {
                    steps {
                        sh 'echo "Hello"'
                    }
                }

                stage('Print ENV variable') {
                    steps {
                        sh "echo ${APP_ENV}"
                    }
                }

            
            }
        }

You can clearly see the parallel execution on blue ocean view.

image 18

How to Generate Jenkins Pipeline Scripts?

It is possible to generate Jenkins pipeline scripts?

Yes! you can generate most of the pipeline scripts from Jenkins. Here is how it works.

Jenkins has its own pipeline script generator. You can access the generator on /pipeline-syntax path.

http://<your-jenkins-ip>:port/pipeline-syntax/

You can also get the syntax generator path from your pipeline job configuration as shown below.

image 19

Snippet Generator

Snippet generator is used for generating all the scripts that are using inside the stages.

Here is how the generator looks. You can select the required option from the steps dropdown, fill in the required details and generate the script to use in your pipeline.

image 20

Declarative Directive Generator

You can use the directive generator to generate all other options in the pipeline. For example, options, parameters, triggers, etc.

Here is an example of generating the agent block.

image 22

Conclusion

Adopting pipeline code for all Jenkins workflows will give more control and streamlined pipelines for your CI/CD need. Extending your pipelines with a shared library lets you reuse the pipeline code for all implementations. Let us know your thoughts in the comment section below.

Jenkins Pipeline as Code Tutorial

How to Configure SSL on Jenkins Server

Configure SSL for Jenkins

It is very important to secure Jenkins by enabling SSL which runs in a project environment. This article walks you through the step by step guide for configuring SSL on a Jenkins server.

Following are the steps involved in configuring SSL on Jenkins server.

  1. Obtain SSL certificates
  2. Convert SSL keys to PKCS12 format
  3. Convert PKCS12 to JKS format
  4. Add JKS to Jenkins path
  5. Configure Jenkins startup to use the JKS file.
  6. Validate Jenkins SSL

Lets get started with the setup

Step 1: Obtain Domain & SSL Certificates

You should have a valid domain pointing to Jenkins server IP to configure SSL. The domain can be internal or external based on your organisations infrastructure.

SSL certificate can be obtained using the following methods.

  1. In most cases, you will be having Jenkins in a private environment with an internal DNS and you can obtain the internal SSL certificates from the respective organizations.
  2. You can also create self-signed SSL certificates using OpenSSL. Follow this blog, generate SSL certificates to create self-signed certificates using OpenSSL.
  3. Also, you can use services as let’s encrypt for valid SSL certificates. But these certificates have to be renewed every three months.

Step 2: Convert SSL keys to PKCS12 format

Note: If you already have the certificate in .p12 or .pfx format, you don’t have to do this conversion.

The command given below converts SSL certs to intermediate PKCS12 format named jenkins.p12. Make sure you have the following certs with you before executing the command.

  1. ca.crt
  2. server.key
  3. server.crt

Also,

  1. Replace jenkins.devopscube.com in the command with your own alias name
  2. Replace your-strong-password with a strong password.
openssl pkcs12 -export -out jenkins.p12 \
-passout 'pass:your-strong-password' -inkey server.key \
-in server.crt -certfile ca.crt -name jenkins.devopscube.com

Step 3: Convert PKCS12 to JKS format

Use the following keytool command to convert jenkins.p12 file to JKS format.

Replace the following with your own values.

  1. -srcstorepass – Password used in Step 3
  2. -deststorepass – Replace with a strong password.
  3. -srcalias – alias name used in step 2
  4. -destalias – Replace with a destination alias name.
keytool -importkeystore -srckeystore jenkins.p12 \
-srcstorepass 'your-secret-password' -srcstoretype PKCS12 \
-srcalias jenkins.devopscube.com -deststoretype JKS \
-destkeystore jenkins.jks -deststorepass 'your-secret-password' \
-destalias jenkins.devopscube.com

You should see a file named jenkins.jks in you current location.

Step 4: Add JKS to Jenkins path

jenkins_keystore.jks file should be saved in a specific location where Jenkins can access it.

Let’s create a folder and move the jenkins_keystore.jks key to that location.

mkdir -p /etc/jenkins
cp jenkins_keystore.jks /etc/jenkins/

Change the permissions of the keys and folder.

chown -R jenkins: /etc/jenkins
chmod 700 /etc/jenkins
chmod 600 /etc/jenkins/jenkins.jks

Step 5: Modify Jenkins Configuration for SSL

All the key Jenkins startup configurations are present in /etc/sysconfig/jenkins file. All the SSL based configurations go into this file.

Open the file

sudo vi /etc/sysconfig/jenkins

Find and replace the values in the file as shown below.

Note: Replace your-keystore-password with the Keystore password, you set in step 3

JENKINS_PORT="-1"
JENKINS_HTTPS_PORT="8443"
JENKINS_HTTPS_KEYSTORE="/etc/jenkins/jenkins.jks"
JENKINS_HTTPS_KEYSTORE_PASSWORD="<your-keystore-password>"
JENKINS_HTTPS_LISTEN_ADDRESS="0.0.0.0"

Save the configuration and restart Jenkins.

sudo systemctl restart jenkins

Check Jenkins status.

sudo systemctl status jenkins

Step 6: Validate SSL

Now you should be able to access Jenkins over https with port 8443

https://<jenkins-dns/ip>:8443

You can also use curl to verify SSL

curl -k https://<jenkins-dns/ip>:8443
Configure SSL for Jenkins