Groovy script in Jenkins

In this article I will host website on kubernetes using Groovy script in Jenkins from docker image. Whole process will be fully automated from creating docker image to exposing website to the client. Hence client can access this website from the webserver created.

Dockerfile for creating a webserver

No alt text provided for this image

Here mysite.html is my website.

Jenkinsfile for building and pushing image automatically.

No alt text provided for this image

Job1: To build and push image to the docker hub.

Create a job ,you must have pipeline plugin installed. Here when you build this job Jenkins will search for Jenkinsfile in Github URL. Then it will build and push the code automatically to the docker hub.

No alt text provided for this image

Job DSL plugin for running the Groovy Script:

Create a job and in build section select Job DSLs for running Groovy script.

No alt text provided for this image
No alt text provided for this image

Job2: Groovy code for copying the code to the server.

No alt text provided for this image

Job3: Creating the webserver from the image uploaded in docker hub in job1

Here the website is hosted using the image using Kubernetes and exposed to the client.

No alt text provided for this image

Job4: Notify the status of the job3 via email.

No alt text provided for this image

YAML file for creating the pods using the image uploaded on docker hub in job1

No alt text provided for this image

Output:

JOB1 Image build and Push.

No alt text provided for this image
No alt text provided for this image

JOB2: Copy of code successfull

No alt text provided for this image

JOB3: Pods created using image of job1 from docker hub.

No alt text provided for this image

JOB4:

No alt text provided for this image

Pods created and Exposed.

No alt text provided for this image

Client can view my site now.

No alt text provided for this image

Github link:https://www.linkedin.com/embeds/publishingEmbed.html?articleId=7318612121778554732



Categories: Uncategorized

Tags: ,

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: