Table of contents
In the previous blog, I explained what CI/CD is. Here's the link to my blog: CI/CD. If you haven't already installed Jenkins on your server, here are the steps to Install Jenkins on your system.
What is a Build Job?
A build job in Jenkins is a repeatable process that automates the building, testing, and deploying of software. It is a collection of steps that are executed in a specific order to create a finished product. Jenkins build jobs can be configured to run on a schedule, or they can be manually triggered.
Many different types of build jobs can be created in Jenkins, including:
Freestyle projects: These are the most basic type of build job, and they allow you to define the steps that are executed in the build process.
Pipelines: Pipelines are a more advanced type of build job that allows you to define the steps in the build process using a declarative syntax.
Multi-configuration projects: These allow you to create multiple builds of the same project, each with different configurations.
Folders: Folders can be used to organize your build jobs.
Multibranch pipelines: These allow you to create pipelines that are based on branches in a Git repository.
Organization folders: These allow you to organize your build jobs by organization.
In this blog, I am going to do a Freestyle Project. Let's learn what a freestyle project is.
What are Freestyle Projects?
A freestyle project in Jenkins is a type of build job that allows you to define the steps that are executed in the build process. Freestyle projects are the most basic type of build job in Jenkins, and they are a good starting point for building more complex pipelines.
Here are a few tasks that you could complete when working with a freestyle project in Jenkins:
Build a software project. Freestyle projects can be used to build web applications, mobile applications, desktop applications, and more.
Run automated tests. Freestyle projects can be used to run automated tests against your software project.
Deploy your software project. Freestyle projects can be used to deploy software projects to a production environment.
Collect metrics about your build process. Freestyle projects can be used to collect metrics about your build process. This information can be used to improve the efficiency and effectiveness of your build process.
Integrate with other tools. Freestyle projects can be integrated with other tools, such as version control systems, continuous integration servers, and continuous delivery servers.
Let's complete today's tasks which include deploying a Django Todo List application.
Tasks
Task 1
Create a new Jenkins freestyle project named ToDoApp.
Configure the project. In the Source Code Management section > Select Git > Enter the GitHub Repository Link and the branch name.
Repo link I have used: Django Todo App.
In the Build Steps section > Select Add Build Steps > Select Execute Shell > And type the commands required for your activity.
docker build -t todoapp . docker run -d --name django-todo-app -p 8000:8000 todoapp:latest
Click on Save and Build your project.
Once the project is built successfully, a green tick can be observed beside the build number.
We can see the console output and steps of the activity.
In the final line of the Console Output, we can observe that Finished: Success is printed. That means our build is successful.
I have verified that the ToDo list application is accessible on host_IP:8000.
Task 2
In task 2, we need to create a Jenkins project to run the "docker-compose up -d" command to start the multiple containers defined in the compose file. Set up a cleanup step in the Jenkins project to run the "docker-compose down" command to stop and remove the containers defined in the compose file.
So in the Add build steps of the configuration section, write in the following command and go ahead and build the project.
docker-compose down
docker-compose up -d
And in the Console Output, we can check the status.
Voila, the build is successful!
In this blog, I have done a freestyle project on Jenkins to deploy a Django application on Docker. If you have any questions or would like to share your experiences, feel free to leave a comment below. Don't forget to read my blogs and connect with me on LinkedIn and let's have a conversation.
To help me improve my blog and correct my mistakes, I am available on LinkedIn as Sneha K S. Do reach me and I am open to suggestions and corrections.
#Day23 #90daysofdevops