# Jenkins Freestyle Project for DevOps Engineers

## **What is CI/CD⁉️**

*Continuous Integration (CI) automates merging code changes from various developers into a single codebase. Developers frequently commit to a central repository (like Github), where automated tools build and review code. CI aims to spot and fix bugs faster, simplify teamwork, enhance software quality, and speed up new feature releases.*

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693145669125/70b90159-bec1-4329-ba74-be3dcc0607ad.avif?auto=compress,format&format=webp align="left")

*Continuous Delivery (CD) follows Continuous Integration, ensuring prompt and error-free delivery of new changes to customers. It involves staging tests, akin to the production environment, to prevent release failures. CD automates releases, maintaining a deployment-ready product for anytime application deployment.*

## **What Is a Build Job⁉️**

*In Jenkins, a build job is a defined task that automates the compilation, testing, and packaging of source code into a deployable artifact. It's a crucial part of the Continuous Integration process, where Jenkins pulls code changes from a repository, triggers the build, and generates executable software, ensuring consistent and reliable results with each commit.*

## **Types Of Jobs ⁉️**

*Jenkins offers various types of build jobs which are given below:-*

1. **Freestyle Project:** *Basic graphical build setup with manual configuration flexibility.*
    
2. *Pipeline:*\*\* *Powerful scripting for complex, adaptable build processes.*
    
3. **Multibranch Pipeline:** *Automates separate pipelines for various code branches.*
    
4. **Parameterized Build:** *Customizes builds based on user-provided parameters.*
    
5. **Scheduled Build:** *Automates tasks at predefined times or recurring intervals.*
    
6. **GitHub Organization:** *Automates GitHub project integration and creation.*
    
7. **Distributed Build:** *Distributes tasks across agents for faster, efficient builds.*
    

## Task 1:

*Set up a Jenkins agent for your app, then create a new freestyle project to automate building and running a Docker container: add a* `docker build` *step to create the image, and a second step to run the container using the image.*

### Creating the agent for app

1. *Access your Jenkins dashboard through a web browser.*
    
2. *Navigate to "Manage Jenkins" and then select "Manage Nodes and Clouds." In this section, you'll be able to create a new agent for your Jenkins setup.*
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693239514365/a565c5e1-efa6-41bc-98ed-5c6b6a914fca.png?auto=compress,format&format=webp align="left")
    
3. **Set Up a New Agent:**
    
    * Click on the "New Node" option.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693239650820/db4672fc-ec0d-4a87-8c44-6d0d7c571201.png?auto=compress,format&format=webp align="left")
        
    * Give a suitable name to the agent (e.g., "Docker-Agent").
        
    * Select "Permanent Agent" and then click "OK."
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693239675185/4972758d-9bc9-4295-be29-824b8e2c1b1c.png?auto=compress,format&format=webp align="left")
        
4. **Agent Configuration:**
    
    * Define the number of executors (simultaneous build processes) for the agent.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693239951854/0ea5c1ec-45bf-4ce9-ae47-820faf049054.png?auto=compress,format&format=webp align="left")
        
    * Select the suitable launch method. For simplicity, you can opt for "Launch agent by connecting it to the master."
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693239963215/e2825fe0-5e51-4de9-bb88-a5c7bbd202b5.avif?auto=compress,format&format=webp align="left")
        
5. Save the Configuration: *Click "Save" to finalize the new agent setup.*
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693239912442/46afa5fd-dad0-45ba-9197-d70231c0044d.avif?auto=compress,format&format=webp align="left")
    

### **Setting Up a Jenkins Freestyle Project**

1. **Login to Jenkins:** *Access your Jenkins dashboard using a web browser.*
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693240656811/161db52d-e29e-4966-b579-5b0fdaca680c.png?auto=compress,format&format=webp align="left")
    
2. **Create a New Project:** *Click on "New Item" to create a new project.*
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693242288839/2b3bbd44-e40b-4c87-bbba-abe021708fa3.png?auto=compress,format&format=webp align="left")
    
3. **Choose Project Type:** *Select "Freestyle project" as the project type and provide a name for your project*.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693240769569/d59165c2-eace-408f-a3e6-71dfdaae45b7.png?auto=compress,format&format=webp align="left")
    
4. **Configure Source Code Management:** *In the project configuration, specify details like the source code repository URL and the branch to build.*
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693241017712/c92c1c50-b3d4-49d7-9fc9-6ff709945c4d.avif?auto=compress,format&format=webp align="left")
    
5. **Define Build Steps:** *Under the "Build" section, add build steps such as executing shell commands or running scripts required for your project.*
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693241865017/6e11f2e6-41c2-4dcc-9bb9-a4866c5f9748.png?auto=compress,format&format=webp align="left")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693241917293/659b8f22-6831-4c03-8ea3-98df782142a4.png?auto=compress,format&format=webp align="left")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693242584149/79abca97-fca6-4723-b34d-f87507b91000.png?auto=compress,format&format=webp align="left")
    
    **Copy**
    
    **Copy**
    
    ```plaintext
     docker build . -t django-app
     docker run -d -p 8001:8001 django-app:latest
    ```
    
6. **Save and Build:** *Click "Save" to create the project. You can manually trigger builds using the "Build Now" button.*
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693242183599/eac66647-c4d2-4906-a168-c62a32eec744.png?auto=compress,format&format=webp align="left")
    
7. **View Console Output:** *Once the build starts, you can monitor the progress and view detailed logs in the console output.*
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693242886011/a67ee0ce-fc06-4b72-87f7-7c6be681d8e9.png?auto=compress,format&format=webp align="left")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693245588389/2af00e59-5feb-4998-bd8d-67e6a696f63b.avif?auto=compress,format&format=webp align="left")
    
    😁😁
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693245610440/1aeaeaef-f4b9-4185-9c0d-3d048fbfe2cf.png?auto=compress,format&format=webp align="left")
    

## Task 2:

*Create a Jenkins project to launch multiple containers using* `docker-compose up -d`*, and include a cleanup step to stop and remove containers with* `docker-compose down` *command.*

**All the step are same just the execute shell script will changes.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693242693316/29e9c5e9-7023-4d02-941a-e4123d665d6e.png?auto=compress,format&format=webp align="left")

**Copy**

**Copy**

```plaintext
echo "code cloned"
docker-compose down
docker-compose up -d --no-deps --build web
echo "code deploy"
```

**Console output:**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693242833667/a1a62163-6e11-42b1-a87a-4ca2ee7cf572.png?auto=compress,format&format=webp align="left")

## Conclusion

*In the world of DevOps, CI/CD revolutionizes software development. Continuous Integration (CI) automates code merging, while Continuous Delivery (CD) ensures seamless delivery to customers. Jenkins, a powerful tool, offers various build job types for efficient development workflows.*

As part of your DevOps journey:

1. **Set Up Agent and Freestyle Project:** *Create a Jenkins agent for your app and build a freestyle project. Automate Docker container building and running.*
    
2. **Create Dockerized Project:** *Launch multiple containers using Jenkins and docker-compose up -d, ensuring easy project management*
