DevOps — CI/CD Pipeline with Groovy

Hey Guys

In this article, I will demonstrate how to implement CI/CD pipeline in Jenkins using Groovy Scripting along with Kubernetes and Git, which will help you to understand the actual meaning of DevOps. so, let’s directly move a use-case which we will solve here.

Use-case Description :

Create a job chain of job1, job2, job3, and job4 using the build pipeline plugin in Jenkins.
2. Seed Job: Pull the GitHub repo automatically when some developers push the repo to GitHub which contains Groovy Script.

3. Further on jobs should be pipeline using written code using Groovy language by the developer.
4. Job1: Fetches the code from GitHub and store on the Workspace.

5. Job2 :

6. Job3: Test your app if it is working or not.

7. Job4: If the app is not working, then send an email to the developer with error messages and redeploy the application after the code is being edited by the developer.

Now, we will discuss each task in brief.

Pre-requisite :

  1. Jenkins should be successfully Installed and configured with root access.
  2. Kubernetes should be properly configured.
  3. Jenkins must have plugins Job DSL, Github, Pipeline, Email Extension, and build pipeline extension.

Jenkins Seed Job :

In this use case, we only have to configure this job. So, let's build Seed Job:

Go to Jenkins and click on “New Item” => give name “Seed Job” => click on Freestyle Project => then ok.

Next, follow the below-mentioned screenshots and put the required information.

Now Enter the Github repository URL in the Source Code Management section and also set the branch name. This will help Jenkins to download your repository.

Enter Github Link for Seed job

Next, Select a trigger to automate seed job build. Here, I used poll SCM because it automatically fetches that code in equal intervals and pulls when on a new commit on GitHub.

Select Trigger for Seed Job

At last, use the “Look on Filesystem” => “DSL Script” option and entered the script file name.

Create DSL script

Now, build the seed job. Output is successful if your script and job configuration are correct.

Now we discuss our Groovy script.

It consists of 3 jobs which are given below.

Groovy Script for Job 1 :

Job 1 Build Pipeline

Groovy Script for Job 2 :

Job 2 Build Pipeline

Groovy Script for Job 3 :

Job 3 Build Pipeline

Groovy Script for Build Pipeline View :

Build Pipeline Creation

So, by using these scripts, you can create the pipeline.

That’s all! ⭐️⭐️⭐️

So, now it’s time to say Goodbye. Now, we will meet soon, in my upcoming blog, until that be happy and safe. 🤗 🤗 🤗

If you like my blog and want such blogs, follow me on medium. 👍👍👍

In the upcoming days I am going to publish lots of articles on Cloud Computing Technologies, AWS, DevOps, Hadoop, and many case-study, So definitely follow me on Medium. 👀👀👀

Here is my LinkedIn profile link and if you have any queries definitely Comment. ✍️✍️✍️

Technical Content Writer || MLOps || Devops || Hybrid Multi Cloud || Flutter || Python || Arth Learner || Technology Lover || Youtuber || Keen & Slow Learner

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store