Day #23: Jenkins Freestyle Project for DevOps Engineers.

ยท

3 min read

What is CI/CD?

  • 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.

What Is a Build Job?

A Jenkins build job contains the configuration for automating a specific task or step in the application building process. These tasks include gathering dependencies, compiling, archiving, or transforming code, and testing and deploying code in different environments.

Jenkins supports several types of build jobs, such as freestyle projects, pipelines, multi-configuration projects, folders, multibranch pipelines, and organization folders.

What are 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.

Task-01 : Jenkins Freestyle Project Configuration

  1. Open Jenkins and create a new freestyle project named "Django-todo-cicd."

  2. In the Source Code Management section, select Git and provide the GitHub repository link along with the branch name.

  3. Repo link I have used: Django-todo-cicd

  4. For the Build Steps section, add an Execute Shell build step and input the required commands for your activity.

  5. Now when you'll build the project you will get the below error

  6. Build the project and address any permission denied errors to /var/run/docker.sock by using the commands:

      sudo chown $USER /var/run/docker.sock
      sudo chmod 777 /var/run/docker.sock
    
  7. Verify application accessibility by checking the running container and accessing host_IP:8000 in your browser.

Task-02 : Enhancing with Docker-Compose

  1. Install Docker-Compose on your instance using:

     sudo apt-get update && sudo apt-get install docker-compose
    

  2. We are using the same above pipeline, just doing some changes, as seen below:

    1. Modify the existing Jenkins freestyle project pipeline by adding Docker-Compose commands.

        docker-compose down
        docker-compose up -d
      

      Save the configuration and run the build to ensure a successful deployment.

    2. So, as you can see the build is successful.

    3. So, these are the two examples on how you can use GitHub repo to fetch the code and deploy your application using docker commands, automating it through Jenkins.

Conclusion

In this blog journey, we've embarked on a freestyle project with Jenkins, orchestrating the deployment of a Django application on Docker. CI/CD, Jenkins build jobs, and Freestyle Projects have seamlessly converged to empower developers in automating and streamlining software development workflows.

As we conclude this exploration, I invite you to share your experiences and insights. Feel free to leave comments, questions, or reflections below, fostering a collaborative space for continuous learning in the ever-evolving landscape of DevOps.

ย