Streamline Your CI/CD Workflow: Building a Simple Jenkins Freestyle Pipeline


This is a straightforward example of setting up a Jenkins Freestyle project for CI/CD, demonstrating how to efficiently manage your build, test, and deployment processes.
Jenkins Freestyle Project
In the context of Jenkins and CI/CD workflows, a "Job" refers to a specific task or a set of tasks that Jenkins executes. A job can include various steps such as building the code, running tests, creating Docker images, or deploying applications to a specified environment.
These jobs are configured with detailed instructions and can be linked together to form a sequential workflow, ensuring that each step in the software development lifecycle is automated and efficiently managed. This approach helps streamline the process from code integration to deployment, enhancing productivity and reducing manual intervention. Each job is configured with specific instructions and can be linked to other jobs to form a complete pipeline, allowing for automated and continuous integration and delivery processes.
Setting Up Jenkins Freestyle Project
Install Jenkins and Docker
Getting Started with Jenkins Using Docker
Steps to Create a Jenkins Job
Begin by creating a new Freestyle project in your Jenkins CI/CD tool. (A Job)
Configuration the project settings as needed
Source Code Management: Provide the correct Repository URL and Branch.
Build Steps: In Build Steps, specify the type of build you want. Use "Execute Shell" to run shell commands.
Set Up Commands: Set up the commands to run when this job is executed and then save the configuration. (These commands will be executed on the server)
After your first build, you can view all the details, such as the build output and the code pulled from the specified Git repository (which you can also check in the Workspace section).
The output shows the location of this specific job on the server.
CI-CD pipeline using Jobs
We will integrate a CI/CD pipeline into this project using Jenkins Jobs. This will be applied to a simple web app built with Flask.
GitHub link- Flask-DevOps-Toolkit
So, we create some jobs where we can configure the necessary steps for building, testing, and deploying our application. Each job can be tailored to perform specific tasks, such as compiling code, running tests, or deploying to a server. By linking these jobs together, we create a seamless CI/CD pipeline that automates the entire process from code commit to deployment.
Setting up the jobs is similar to what is described above, except the Build Steps will be different and will include some triggers.
Also, remember to provide the correct repository URL and branch for your project.
Setting up Jobs:
Build and Test Job
This job is responsible for compiling and testing the application.
In this case, it's a Python test case that needs to be checked. If it passes, the build succeeds; if not, it fails.
Build Image Job
This job is triggered to build a Docker image of the application.
In this case, the docker build
command is used to create a Docker image for the project. When this build is triggered, it generates an image as shown below.
Deploy Application Job
Set up a deployment job to deploy the application to your desired environment.
In this case, the docker run
command is used to run the application on the desired port and environment.
Connecting Jobs
The process of connecting these jobs involves setting them up in a sequence to form a complete pipeline. Here's how the jobs are connected in your project:
Build And Test Job: This job is responsible for compiling and testing the application.
Build Image Job: After the Build and Test job completes successfully, this job is triggered to build a Docker image of the application.
Deploy App Job: Once the Docker image is built, this job is triggered to deploy the application to the desired environment.
The jobs are linked in a sequence: Build and Test → Build Image → Deploy Application. This sequential linking ensures that each step in the CI/CD process is executed in the correct order, allowing for automated and continuous integration and delivery.
Build And Test Job Triggers
As we have configured the job, it's now time to set the triggers that will automatically initiate the process whenever changes are made in the repository
Build Periodically Trigger-
We are using a cron job to schedule the build every minute for testing purposes (not recommended for production).
Visit https://crontab.guru/ - For more cron job configuration
Poll SCM Trigger-
Same as Build Periodically just it keeps on checking every minute for a change in Git Repository. (Not recommended either)
We will use the Poll SCM trigger here.
This will run unit test cases every time there is a change in the code in the repository.
Build Image Job Triggers
After the Build and Test job finishes successfully, this job starts to create a Docker image of the application.
Ensure the job is triggered after the Build And Test Job completes successfully.
Here, we need to select the "Build after other projects are built" trigger, and the project to monitor will be "BuildAndTest." This means, if this build is stable, then proceed to build the Docker image.
Upstream and Downstream projects-
In Jenkins, an "upstream project" is a project that triggers another project, known as the "downstream project." When the upstream project completes successfully (BuildAndTest), it can automatically trigger the downstream project (BuildDockerImage) to start. This setup is useful for creating a sequence of jobs where the completion of one job initiates the next, allowing for a streamlined and automated workflow in a CI/CD pipeline.
Deploy Application Job Trigger
Once the Docker image is created, this job automatically starts to deploy the application to the chosen environment.
Here also, we need to select the "Build after other projects are built" trigger, and the project to monitor will be "BuildDockerImage." This means, if the Docker image build is successful, then proceed to deploy the application. This setup ensures that only stable builds are deployed, maintaining the integrity of the deployment process.
Here, we can also see the upstream and downstream projects associated with "DeployApp."
Now the pipeline setup is complete. If everything is configured correctly, each step will trigger the next one automatically, ensuring a smooth and efficient deployment process.
Build Stability
On the dashboard, you can see each job's build stability with percentages and icons that reflect the stability of recent builds.
Visualizing the Pipeline
It's easier to manage when visualized!
Install Visualization Plugin: Navigate to the plugin management section, find the available plugins, and install the visualization plugin “Build Pipeline”.
Use the Plugin: Use the plugin to view and manage the pipeline flow. Click on the plus icon to choose a new view from the dashboard and select the Build Pipeline View to create a pipeline view.
Use the plugin to view and manage the pipeline flow.
Pipeline Execution:
Run the pipeline to see the flow of CI/CD from build to deployment.
Make changes in the code to test the automatic flow of CI/CD.
Monitor the pipeline execution using the visualization tool to ensure all steps are completed successfully.
Execution Phase-
Completed Pipeline-
Best Alternatives to Build Pipeline Plugin
Blue Ocean
Modern, user-friendly UI for Jenkins pipelines.
Graphical visualization with a clean interface.
Actively maintained.
Install:
Blue Ocean
plugin.
Pipeline: Stage View
Graph-based view of pipeline stages.
Works with Declarative Pipelines.
Shows stage durations, logs, and failures.
Install:
Pipeline Stage View
plugin.
Delivery Pipeline Plugin
Ideal for Continuous Delivery workflows.
Real-time pipeline visualization.
Install:
Delivery Pipeline Plugin
.
View Job Filters Plugin
Organizes Jenkins jobs into categories.
Useful for managing large projects.
Install:
View Job Filters Plugin
.
Which One Should You Choose?
✅ If you want a modern, easy-to-use UI → Blue Ocean
✅ If you use Jenkins Declarative Pipelines → Pipeline Stage View
✅ If you need Continuous Delivery (CD) visualization → Delivery Pipeline Plugin
Conclusion
In summary, a Jenkins Freestyle pipeline effectively automates the CI/CD process, enhancing productivity and reducing manual tasks. By linking jobs for building, testing, and deploying, you create a streamlined workflow that ensures efficient and reliable software delivery
Subscribe to my newsletter
Read articles from Jasai Hansda directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Jasai Hansda
Jasai Hansda
Software Engineer (2 years) | In-transition to DevOps. Passionate about building and deploying software efficiently. Eager to leverage my development background in the DevOps and cloud computing world. Open to new opportunities!