Jenkins Freestyle Project for DevOps Engineers

Jenkins Freestyle Project for DevOps Engineers

Day 23: #90DaysOfDevOps Challange

What is CI/CD?

CI/CD stands for Continuous Integration/Continuous Delivery (or Continuous Deployment) and is a software development approach that aims to automate and streamline the process of building, testing, and deploying code changes.

Continuous Integration refers to the practice of regularly merging code changes from multiple developers into a shared repository, where automated builds and tests are run to detect any issues or conflicts early on.

Continuous Delivery, on the other hand, is the practice of automatically deploying code changes to production environments after they have been tested and validated. This ensures that the code is always ready to be released to end-users, without any delays or manual intervention.

Continuous Deployment takes this one step further by automating the release process so that code changes are automatically pushed to production as soon as they pass all tests and checks.

CI/CD is an essential part of modern software development, as it allows teams to move faster, improve code quality, and reduce the risk of errors and downtime.

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 is 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. Here are a few tasks that you could complete when working with a freestyle project in Jenkins:

Task 1: Create a new Jenkins freestyle project for your app. 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 2.

  1. Log in to Jenkins:

    • Open your web browser and navigate to the URL of your Jenkins instance (publicIPadress:8080) As shown below.

    • Log in using your Jenkins username and password.

  2. Create a new Jenkins Freestyle Project:

    • Click on "New Item" on the Jenkins dashboard.

    • Enter a name for the project in the "Enter an item name" field, for example, "node-todo-cicd".

    • Select "Freestyle project" and click "OK".

  3. Configure the Jenkins Freestyle Project:

    • In the "General" tab, select "Git hub " and enter the github link

    • In the "Source Code Management" tab, select "Git" and enter the URL of your Git repository.

    • In the "Build" tab, click on "Add build step" and select "Execute shell".

    • Enter the following command to build the Docker image:

        docker build -t node-todo-cicd:latest .
      
    • Add a second build step to start a container using the image:

        docker run -d -p 8000:8000 node-todo-cicd:latest
      

  4. Save the Jenkins Freestyle Project:

    • Click on "Save" to save the project configuration.
  5. Build the Jenkins Freestyle Project:

    • Click on "Build Now" to start the build process.

    • Jenkins will run the build steps and display the console output in real-time.

    • Once the build is complete, you can access your Node-Todo-CICD app by navigating to http://<Jenkins-server-IP-address>:8080.

Task 2: Create Jenkins project to run "docker-compose up -d" command to start the multiple containers defined in the compose file (Hint- use day-19 Application & Database docker-compose file) .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.

To create a Jenkins project to run "docker-compose up -d" command, and a cleanup step to run "docker-compose down", you can follow these steps:

  1. Log in to your Jenkins server and create a new freestyle project.

  2. Give your project a name ("node-todo-app-deployment") and click "OK".

  3. In the "General" section of the project configuration, check the "GitHub project" box and enter the URL of your GitHub repository.

  4. In the "Source Code Management" section, select "Git" as the repository type and enter the URL of your GitHub repository. Optionally, you can specify the branch to build.

  5. In the "Build" section, click the "Add build step" drop-down menu and select "Execute shell".

  6. In the "Command" text box, enter the following command to start the containers defined in the Docker Compose file:

  7. Click "Save" to save the project configuration.

Now, when you run the Jenkins project, it will start the containers defined in the Docker Compose file using the "docker-compose up -d" command, and stop and remove the containers using the "docker-compose down" command when the build finishes.

That's it! 🎉🎉✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨✨You have successfully created a Jenkins freestyle project for your Node-Todo-CICD app and added build steps to build the Docker image and start a container using the image as well as using docker compose

Did you find this article valuable?

Support Dhananjay Kulkarni by becoming a sponsor. Any amount is appreciated!

Â