Build a Full CI/CD Pipeline with Docker and Jenkins from Scratch
This guide explains the fundamentals of CI/CD pipelines within DevOps, walks through each stage from code commit to production deployment, and provides a step‑by‑step tutorial using Jenkins and Docker to automate building, testing, and releasing a web application.
Implementing a CI/CD (Continuous Integration/Continuous Deployment) pipeline is the foundation of modern DevOps, automating application build, test, and deployment to bridge development and operations teams.
Understanding DevOps and Its Lifecycle
DevOps is a software development approach that includes continuous development, testing, integration, deployment, and monitoring throughout the software lifecycle, enabling high‑quality software, shorter development cycles, and higher customer satisfaction.
The DevOps lifecycle connects each software development phase, illustrated by diagrams (images omitted for brevity).
What CI/CD Means
CI stands for Continuous Integration, while CD can refer to Continuous Delivery or Continuous Deployment, representing a process similar to the software development lifecycle.
The pipeline moves software through stages—code commit, build, test, and deployment—until it reaches the production environment.
Typical CI/CD Workflow Example
Assume a web application is being built and deployed to an online server. Developers commit code to a version‑control system (e.g., Git or SVN). The code then enters the build stage, where it is compiled (for Java, using tools like Maven) and version‑tagged.
After building, the code proceeds to testing, which includes functional, unit, and usability tests. Once tests pass, the code is deployed to a staging or test server for further verification, and finally to production if everything is successful.
If any step fails, the team receives an email notification, fixes the issue, and re‑submits the code to the pipeline.
CI Tools and Their Importance
Automation tools are required to achieve end‑to‑end DevOps pipelines. Jenkins provides interfaces and plugins to automate the entire software delivery process.
Typical Jenkins workflow:
Configure a Git repository as the source.
Jenkins pulls the code, builds it (using Maven for Java), runs tests, and packages the artifact.
The artifact is stored in a cache server and deployed using Docker.
Docker creates lightweight virtual environments where servers and test artifacts can be built and run within seconds.
Hands‑On: Building a CI/CD Pipeline with Docker and Jenkins
Start Jenkins and Docker services on the VM:
systemctl start jenkins
systemctl enable jenkins
systemctl start dockerOpen Jenkins on the designated port and click “New Item” to create a new job.
Select “Freestyle project”, name it (e.g., Job1), and confirm.
Configure Source Code Management to point to the Git repository, then apply and save.
In the Build section, add an “Execute Shell” step.
Enter shell commands to archive the source, generate a WAR file, pull code, and use Maven to install dependencies and compile the application.
Repeat the above steps to create additional jobs (Job2, Job3) for subsequent pipeline stages.
For each job, configure post‑build actions to “Build other projects” (Job1 → Job2 → Job3) and save.
Create a “Build Pipeline View”, name it (e.g., CI CD Pipeline), set the initial job to Job1, and run the pipeline.
After a successful build, access the application at http://localhost:8180/sample.text.
By following these steps, you can set up a complete CI/CD pipeline using Docker and Jenkins, achieving faster, more reliable software delivery and fostering closer collaboration between development and operations teams.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITFLY8 Architecture Home
ITFLY8 Architecture Home - focused on architecture knowledge sharing and exchange, covering project management and product design. Includes large-scale distributed website architecture (high performance, high availability, caching, message queues...), design patterns, architecture patterns, big data, project management (SCRUM, PMP, Prince2), product design, and more.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
