A modular, scalable, and reproducible Jenkins setup using Docker Compose, designed for efficient CI/CD environments.
This setup provides a fully containerized, automated Jenkins infrastructure that can be:
- ✅ Built once, deployed anytime – Spin up a new Jenkins instance effortlessly.
- ✅ Lightweight & stateless – Jenkins runs in a clean, pre-configured container.
- ✅ Automated & self-testing – Ensures Jenkins is functional before executing builds.
- ✅ Scalable & modular – Uses Docker-in-Docker (DinD) and dynamic agent provisioning.
- Runs in a Docker container with a minimal setup.
- Configured via Jenkins Configuration as Code (CASC).
- Does not have the Docker CLI installed (agents handle that).
- Health checks ensure it is up and running before use.
- Runs as a separate service to execute Docker commands for builds.
- Jenkins agents connect to DinD instead of the host system.
- Uses an insecure registry setting to work with the private registry.
- Spun up inside the DinD environment to execute builds.
- Uses a custom-built agent image, stored in a private registry.
- Allows scalability by running multiple agents in parallel.
- Stores the Jenkins agent image and other build artifacts.
- Used to cache dependencies and speed up builds.
- Runs a health check to ensure availability before Jenkins starts.
- Builds the Jenkins agent image before deployment.
- Pushes the image to the private Docker registry.
- Ensures that a valid agent image exists before Jenkins starts.
- Runs basic tests to validate the Jenkins setup.
- Ensures Jenkins starts up correctly before allowing deployment.
- Executes
jenkins-sanity-check-pipeline
to verify the setup further.
- After the initial build, Jenkins can be deployed instantly using Docker Compose.
- No need for manual configuration – CASC takes care of everything.
- The system self-tests at every stage to ensure reliability.
This pipeline runs essential tests before allowing further builds:
- ✅ Ensures the job does not run on the master node.
- ✅ Verifies workspace and checks file creation.
- ✅ Confirms required Jenkins plugins are installed.
- ✅ Runs parallel jobs to test concurrent execution.
- ✅ Checks if Docker is running and accessible.
🛠 How it Works:
- The pipeline is triggered with every push to GitHub via GitHub Actions.
- If any test fails, the build is marked as failed, preventing further execution.
- Jenkins Controller running on
http://jenkins:8080
- Jenkins Agent(s) configured with the required labels
- Docker installed and accessible on relevant agents
- Required Jenkins Plugins installed and up to date
- Network connectivity between the Jenkins controller and agents
- ✅ Ensures the job is not running on the master node
- ✅ Confirms execution on an expected agent node (
docker-agent
,agent-on-hostnet
, etc.)
- ✅ Verifies that the workspace is functional by creating a test file
- ✅ Checks that the Jenkins agent can reach the controller (
http://jenkins:8080/login
)
- ✅ Reads
plugins.txt
to validate that all required plugins are installed - ✅ Identifies missing or outdated plugins
- ✅ Runs parallel jobs to ensure Jenkins can handle concurrent tasks
- ✅ Ensures Docker is installed and running
- ✅ Validates that the agent running Docker can communicate with the Jenkins controller
- Navigate to Jenkins
- Trigger the
jenkins-sanity-check-pipeline
job - Monitor the results in the console output
- Address any reported issues before proceeding with other builds
- If the pipeline fails on node validation, ensure jobs are assigned to a valid agent.
- If the workspace check fails, verify that the agent has write access.
- If the network test fails, check agent connectivity to the controller.
- If plugin validation fails, install the missing plugins manually or update outdated ones.
- If Docker connectivity fails, ensure the agent has Docker installed and properly configured.
This setup creates a portable, pre-configured, and self-testing Jenkins infrastructure that:
-
🚀 Works out of the box – Deploy it on any machine and get a working Jenkins setup instantly.
-
🛠️ Minimizes manual intervention – No need for post-setup tweaks or agent setup.
-
🔄 Ensures reliability – Built-in tests and the sanity check pipeline help prevent common issues before running production builds.
-
💡 Scales dynamically – Agents are provisioned as needed inside DinD, ensuring flexibility and scalability.
This automated and self-verifying setup ensures that your Jenkins environment is always ready for production builds, minimizing potential issues and streamlining your CI/CD workflows.