Jenkins Freestyle Project for DevOps Engineers (Part 2)

Jenkins Freestyle Project for DevOps Engineers (Part 2)

Today, as we begin our journey with Jenkins, we'll be immersing ourselves in the realms of continuous integration and continuous delivery/deployment.

What is CI/CD?

Continuous integration and continuous delivery or deployment are like supercharged helpers for software development. They automate different stages of the software creation journey, handling bug fixes and speedy updates, while also keeping things organized across various environments like development, testing, staging, and the big leagues: production.

In the CI part of things, when developers add new stuff to the source code, the system snags that code and gets it ready for action. It sets up all the necessary bits, builds the final product, runs some tests to make sure it’s good to go, and then packages it up neatly.

Once that's done, CD steps in to take this polished creation and send it off to its various destinations—different stages of testing and deployment. This whole process keeps on chugging along, making sure everything's running smoothly and continuously.

What Is a Build Job?

Within Jenkins, a build job is essentially a set of instructions that automate a particular job or phase within the app-building journey. This can involve various tasks like rounding up dependencies, compiling code, storing or changing code, and finally, putting it to the test and sending it off to different places.

Jenkins is pretty versatile, offering different types of build jobs to suit different needs. There are freestyle projects, pipelines, multi-configuration projects, folders to organize stuff, multibranch pipelines, and organization folders, all serving different purposes in the building process.

What is Freestyle Projects ??

A freestyle project in Jenkins is a type of project that allows you to build, test, and deploy software using a variety of different options and configurations. Here are a few tasks that you could complete when working with a freestyle project in Jenkins

Task-01

  • create an agent for your app. ( which you deployed from docker in the earlier task)

    - To create an agent we have created a new instance and will use it as an agent.

    - on the new machine will copy id-rsa.pub key from the master server to authorized_keys.

    -Now we can able to communicate Jenkins-agent and Jenkins-Master.

    - Will set up Agent with the below steps

    in Host, we will mention the public IP address of the Jenkin-agent instance.

    post successful configuration give relaunch to an agent to test the connection.

    - To add Jenkins-agent to execute the existing demo project we will add label as below.

    - Post execution of job we can see the log as below.

Task 2:

  • Create a new Jenkins freestyle project for your app.

  • In the "Build" section of the project, add a build step to run the "docker build" command to build the image for the container.

  • Add a second step to run the "docker run" command to start a container using the image created in step 3.

-Solution-

  1. for the above task, we will keep our source code (todo-app) in GitHub repository.

  2. now we build a fresh pipeline with free-style and provide

    a.Github details

    b.Agent Details

    c. docker task like build image and run image using shell execute option

    d. Run pipeline and check our code is successfully deployed and able to access through web page.

    Log

    Our code has been deployed over Jenkins-agent we can navigate using public ip:800

    Our pipeline successfully created images and containers in the agent workspace we can verify the same.

    Task-02

    • Create Jenkins project to run "docker-compose up -d" command to start the multiple containers defined in the compose file (Hint- use day-19 Application & Database docker-compose file)

    • Set up a cleanup step in the Jenkins project to run "docker-compose down" command to stop and remove the containers defined in the compose file.

-Solution

We will create docker-compose file in the repository and use docker-compose command to run the job.

- I have created below docker-compose-test.yaml file through which I will create 2 container

a. Web-NGINX

b. DB-Postgres

- Now we pass docker-compose command in the pipeline for execution.

- Will execute Job and check log now.

we could see as per our docker-compose file we could see 2 containers got created with a single file through Jenkins

I'm hopeful that today's task has provided us with hands-on, real-world project experience. We went ahead and put our source code onto the web using Jenkins CI/CD. Our process involved leveraging Docker to construct an image and deploy it onto an EC-2 instance through the docker-compose utility. With just a single command, we managed to deploy two containers, streamlining the entire process.

Thanks,

Kishor Chavan