Jenkins Freestyle Project for DevOps Engineers

Jenkins Freestyle Project for DevOps Engineers

  1. What is CI/CD?

  • CI (Continuous Integration) is the practice of automating the integration of code changes from multiple developers into a single codebase. It involves developers frequently committing their work into a central code repository (such as GitHub or Stash).

  • Automated tools then build the newly committed code and perform tasks like code review, ensuring that the code is integrated smoothly.

  • The key goals of Continuous Integration are to find and address bugs quickly, make the integration process easier across a team of developers, improve software quality, and reduce the time it takes to release new features.

  • CD (Continuous Delivery) follows Continuous Integration and ensures that new changes can be released to customers quickly and without errors.

  • This includes running integration and regression tests in a staging environment (similar to production) to ensure the final release is stable.

  • Continuous Delivery automates the release process, ensuring a release-ready product at all times and allowing deployment at any moment.


  1. What Is a Build Job?

  • In Jenkins, a build job is an automated process that manages the various stages of software development, including building, testing, and deploying applications.

  • It is configured to source the code from a repository, trigger builds based on specific conditions (such as code changes or scheduled times), and define the environment settings necessary for the build.

  • The build job includes steps to compile the source code, run tests to ensure functionality, and package the code into a distributable format.

  • Post-build actions can involve archiving the build artifacts, deploying them to staging or production environments, and sending notifications to team members about the build status.

  • This automation helps ensure consistent, repeatable builds, reduces manual errors, and accelerates the overall development process.


  1. Task 1 : Freestyle project

  • Create an agent for your app (which you deployed using Docker in a previous task).

  • 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 the previous step.


Create an agent for your app (which you deployed using Docker in a previous task).

  • Setup agent, Visit Blog.

  • Below steps on agent,

  • Install Java and Docker.

  • Setup of agent on Jenkins UI,

  • Agent configured for the build.


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.

  • Create index.html file on master as sample source code.
<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
    <title>Welcome to Nginx!</title>
</head>
<body>
    <h1>Hello, Dockerized Nginx!</h1>
</body>
</html>
  • Create Dockerfile
# Use the official Nginx image from the Docker Hub
FROM nginx:alpine

# Copy the custom index.html to the Nginx default HTML location
COPY index.html /usr/share/nginx/html/index.html

# Expose port 80 to the outside world
EXPOSE 80

# Command to run when the container starts
CMD ["nginx", "-g", "daemon off;"]
  • Execute shell commands,
echo "Building docker image...."
docker build -t nginx:v1 .

echo "Removing old image...."
docker stop nginx && docker rm nginx

echo "Executing docker container"
docker run -d --name nginx -p 80:80 nginx:v1
  • Build the Job.

  • Try to access nginx homepage,


  1. Task 2 : Docker Compose

  • For more details find detailed blog.

Connect with Me

LinkedIn | GitHub

Follow me for more amazing content :)