Jenkins Freestyle Project for DevOps Engineers

Deepesh GuptaDeepesh Gupta
3 min read

Day 25: Jenkins Freestyle Project for DevOps Engineers

Understanding a Build Job?

A Jenkins build job defines the configuration required to automate specific tasks within the application build process. These tasks typically include:

  • Gathering dependencies

  • Compiling and archiving code

  • Transforming source code

  • Running tests

  • Deploying to various environments

Jenkins provides multiple types of build jobs, such as:

  • Freestyle projects

  • Pipelines

  • Multi-configuration projects

  • Folders

  • Multibranch pipelines

  • Organization folders

What is a Freestyle Project? ๐Ÿค”

A freestyle project in Jenkins is a flexible option for building, testing, and deploying software. It allows for different configurations and steps to be executed. Here's an example of what you can achieve with a freestyle project.

Tasks:

Task1: Creating Jenkins Freestyle Project

  • Set up an agent: Make sure to configure an agent where your job will run.

  • Create a new freestyle project:

    • From the Jenkins Dashboard, navigate to:
      New Item โ†’ Freestyle Project โ†’ Enter a project name โ†’ Create.
  • Configure the build step:

    • Scroll to the "Build" section.

    • Choose the Execute Shell option.

    • Enter the following commands to build and run a Docker container:

        cd /home/ubuntu/django-notes-app  # Path where the project is cloned
        docker build -t my-app .
        docker run -d -p 8080:8080 my-app
      
  • As seen below we have the Console Output and Stage output (Build no. 11) which shows that our project ran successfully.

  • Application is also running fine on the port mentioned. To access the application type the following in browser: https://<host-ip>:<port-number>

    Task2: Running Docker Compose

    1. Ensure that docker compose is installed on the agent on which the job will run.

    2. Create Jenkins Project for Docker Compose:

      • We have already created a Freestyle Project as above.

      • Click on that Project -> Configure and in Build section -> Execute shell commands make the below changes.

    3. Run docker-compose down and docker-compose up -d Command:

        << comment
        We run this command first as due to above TASK1 build, container
        will already be running so we need to stop that first and then run 
        again to test docker compose. Note: Make sure to remove docker run
        command from execute shell written before, before writing compose commands.
        comment 
      
        docker-compose -f path/to/your/docker-compose.yml down
        docker-compose -f path/to/your/docker-compose.yml up -d
      

      Conclusion

      Today was Day of DevOps, where we deep dived about what is a freestyle project and a build job and also did a small task to have practical hands on and be confident in it. I hope I was able to help you and guide you in this. For any queries please feel to reach me out on Linkedin.

      Happy Learning, Happy growth!!

0
Subscribe to my newsletter

Read articles from Deepesh Gupta directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Deepesh Gupta
Deepesh Gupta

DevOps & Cloud Enthusiast | Open Source Contributor | Driving Technological Excellence in DevOps and Cloud Solutions