Jenkins Pipeline with Groovy

Task Description:-

Step 1:

In this step we need to create container image that’s has Jenkins installed using Dockerfile.

Configuration file for kubectl

Now we need to build the image from the docker file using build command

docker build -t jenkins-kubectl:v1 .

From the image build we need to launch a container and then configure the jenkins.

For launching the container

docker run -it — name jenkinsos -p 8081:8080 jenkins-kubectl:v1

Now we need to setup the jenkins.

Step 2:

In this step we will will install the required plugin(Github, job-DSL and build-pipeline plugins) that will help us in running the groovey code but before that we need to disabled in the security settings of the Jenkins so that the built script can be run.

Now we will configure the seed job which will run the groovey code pulled from the github and then will create the job chain.

Console output of seed job

This job will create the other jobs .

Job 1: Pull the Github repo automatically when some developers push repo to Github.

Job 2 : This job will launch the container on the top of kubernetes by looking at the program file of the code. And then it will expose your pod so that testing team could perform the testing on the pod and also make the data to remain persistent using PVC.

For launching the pod and creating pvc and also exposing the pods I have craeted a yml code.

Job 3 : This job will test the app if it is working or not and if app is not working file then it will send the mail.

Job4 : If app is not working, the redeploy the application after code is being edited by the developer

Build pipeline of Job1, Job2, Job3:

The output of webapp

Github Link for Groovey Code:

Thank You!!!



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
Aditya Raj

I'm passionate learner diving into the concepts of computing 💻