Skip to main content

Command Palette

Search for a command to run...

#Day 23 - Jenkins Freestyle Project For DevOps Engineer

Published
3 min read
#Day 23 - Jenkins Freestyle Project For DevOps Engineer
A

Passionate AWS Developer | DevOps Engineer with a strong background in cloud architecture and solutions engineering. Leveraging the power of Amazon Web Services (AWS), knowledge of the AWS global infrastructure, design and implement robust cloud-based solutions that align with clients' specific needs.

What is CICD

  • CI or Continuous Integration is the practice of automating the integration of code changes from multiple developers into a single codebase. It is a software development practice where the developers commit their work frequently into the central code repository (Github or Stash). Then there are automated tools that build the newly committed code and do a code review, etc as required upon integration. The key goals of Continuous Integration are to find and address bugs quicker, make the process of integrating code across a team of developers easier, improve software quality and reduce the time it takes to release new feature updates.

  • CD or Continuous Delivery is carried out after Continuous Integration to make sure that we can release new changes to our customers quickly in an error-free way. This includes running integration and regression tests in the staging area (similar to the production environment) so that the final release is not broken in production. It ensures to automate the release process so that we have a release-ready product at all times and we can deploy our application at any point in time.

Task 01:

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

Create a new Jenkins freestyle project for your app.

First of all, install docker in the server then do the docker run and docker build.

sudo apt-get install docker.io
sudo apt-get install docker-compose
sudo usermod -aG docker jenkins
sudo reboot

Open the jenkins server.

Click on New->enter name -> select freesyle project.

In the Source Code Management section > Select Git > Enter the GitHub Repository Link and the branch name.

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.

In the build section > Select Add Build Steps > Select Execute Shell > And type the commands required for your activity.

echo "code build..."
docker build . -t to-do-app

echo "code run..."
docker run -d -p 8000:8000 to-do-app

Click on save and build your app.

Once the project is built successfully, a green tick can be observed beside the build number.

Go to the console output and see the logs and success message

In the last line of the Console Output, we can observe that Finished: Success is printed. That means our build is successful.

Now copy the jenkins_server_ip and exeute on the browser like- jenkins_server_ip:8000. Here we observe that the django-todo-app is running.

So we have created a freestyle django-todo-app as shown.

Task 02:

Create Jenkins project to run "docker-compose up -d" command to start the multiple containers defined in the compose file.

Continue with the same application

Go to the build step and enter the following.

docker-compose down
docker-compose up -d

Now, Click on Build now and then go to console output to see the output.

As we can see the build is successful and the container is created with a Success message

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.

We need to kill and remove your previous container using these commands.

docker ps
docker kill <container id> && docker rm <container id>

Now the previous container is deleted.

Go to the Build Now option and check the console output.

Here we can see in the console output that the build is successful with a SUCCESS message.

Again we can see after the build is success the docker container is created by using the command docker ps.