Skip to content

Jenkins

Setting Up Jenkins on Docker Compose

Jenkins is an open-source automation server widely used for continuous integration (CI) and continuous delivery (CD) in software development. It allows developers to automate the process of building, test, and deploying software applications by integrating with version control systems and other tools.

Key Features of Jenkins

  • Open-source and Extensible - Jenkins is open-source and has a large communit of contributors. Its functionality can be extended with over 1000 plugins available for integration with various tools and platforms.

  • Automation - Jenkins automates repetitive tasks like building code, running tests, and deploying applications, enabling faster and more reliable software development

  • Continuous Integration & Continuous Delivery - Jenkins supports CI/CD pipelines, ensuring code changes are automatically integrated, tested and delivered in a streamlined workflow.

  • Distributed Builds - Jenkins can distribute tasks across multiple machines, speeding up build and test times.

  • Pipeline as Code - With Jenkins, can you define the entire build, test, and deployment pipeline as a code using a jenkinsfile, ensuring version control and easy maintenance.

  • Extensive Plugin Support - Jenkins has plugins for popular tools and services like Git, Docker, Kubernetes, Maven and Slack, enhancing its integration capabilities.

Jenkins Use Cases

  • Continuous Integration (CI) - Jenkins integrates codes from multiple developers, running automated tests and ensuring that new code doesn’t break the build.

  • Continuous Delivery (CD) - It automates the deployment process, allowing code changes to be delivered to production automatically after passing the necessary tests.

  • Automation of Development Processes - Jenkins is used for automating tasks such as code quality checks, static code analysis, and performance testing.

  • Monitoring & Reporting - Jenkins provides real-time feedback on builds and test results, helping teams identify and resolve issues quickly.

Jenkins Workflow

  • Code - Developers write code and push it to a version control system (e.g. Git)

  • Build - Jenkins automatically triggers a build whenever there is a code commit

  • Test - Automated tests run to verify that the code works as expected.

  • Deploy - If the tests pass, Jenkins can deploy the application to a staging or production environment

  • Feedback - Jenkins provides real-time feedback to the team via notifications (e.g. Email, Slack) on the status of the build and tests.

Benefits of Jenkins

  • Faster Development Cycles - Automating builds, tests and deployments significantly reduces the time it takes to deliver software

  • Improved Code Quality - Automated testing and code analysis in Jenkins helps catch errors early in the development process.

  • Scalability - Jenkins can handle complex workflows and large-scale projects by distributing builds and tasks across multiple nodes.

  • Customizable - With its extensive plugin library, Jenkins can be customised to fit various development environments and workflows.

Jenkins Architecture

  • Master - The Jenkins Master is the brain of Jenkins, responsible for scheduling jobs, dispatching builds to the agents, and monitoring the overall status of jobs.

  • Agents (Slaves) - Jenkins Agents run the jobs that the master delegates. These agents can run on different platforms and environments, enabling distributed builds.

In summary, Jenkins is a powerful and flexible tool for automating the entire software development lifecycle, from code integration to deployment, making it a core part of modern DevOps practices.

Why Choose Jenkins

Choosing Jenkins as an automation server brings serveral benefits to teams and organisations, particularly those focusing on continuous integration (CI) and continuous delivery (CD). Here’s why jenkins is a popular choice:

  • Open Source and Free

    • Jenkins is an open-source tool, meaning its free to use, and it benefits from a strong community of developers contributing to its improvement. Organisations can use jenkins without incurring licensing fees, making it cost-effective solution.
  • Extensive Plugin Ecosystem

    • Jenkins offers over 1000 plugins that allow seamless integration with various tools and technologies across the DevOps toolchain, including version control systems (Git, SVN), build tools (Maven, Gradel), testing frameworks (JUnit, Selenium), and deployment platforms (Docker, Kubernetes)
    • This flexibility makes it easy to extend Jenkins to meet the specific needs of almost any development or IT Infrastrcture
  • Strong Community & Support

    • Jenkins has a large and active community that continuously contributes to its development and maintenance. This strong community support ensures frequent updates, bug fixes, and plugin enhancements.
    • Comprehensive documentation and numerous tutorials, guides, and forums make learning and troubleshooting easier for users at all levels.
  • Cross-Platform Support

    • Jenkins is platform-agnostic, supporting various operating systems like Windows, macOS, and Linux. It can easily integrate with cloud platforms (AWS, GCP and Azure) or run in containerised environments (Docker, Kubernetes), given teams freedom to use it in any environment.
  • Automation of CI/CD Pipelines

    • Jenkins automates the continuous integration process by automatically building and testing coding after every commit. This ensures that code is integrated frequently and potential issues are identified early.
    • It also automates continuous delivery, allowing developers to rapidly deploy their applications to various environments (staging, production) without manual intervention.
  • Scalability

    • Jenkins is highly scalable. Its distributed architecture allows build processes to run across multiple agents (or nodes), enabling faster builds, parallel executions, and high availability.
    • As teams and projects grow, Jenkins can scale to meeting increasing demands by adding more agents to distribute the workload.
  • Pipeline as Code

    • Jenkins allows users to define their build, test, and deployment pipelines as code using the Jenkinsfile. This offers serveral advantages, including:
      • Version Control - Pipelines can be stored in the same respository as the source code, enabling easy tracking of changes.
      • Reusability - Teams can reuse and share pipeline configurations across different projects.
      • Maintainability - Storing pipelines as code makes it easier to review, update, and troubleshoot build and deployment processes.
  • Flexibility in Configurations

    • Jenkins supports both GUI-based configuration as well as declarative and scripted pipeline syntax. This flexibility allows developers to choose how they want to define and manage their CI/CD pipelines, based on their preferences or project needs
  • Distributed Builds

    • Jenkins supportss distributed builds, meaning it can run jobs on multiple servers or machines. This is especially useful for large-scale projects with complex builds that need to be split across multiple environments, speeding up the entire CI/CD process.
  • Highly Customisable

    • Jenkins is fully customisable and can be tailored to fit any specific project requirement, whether its integrating with cloud services, monitoring system resources, or setting up specific workflows for different development teams.
  • Real-Time Monitoring & Reporting

    • Jenkins offers real-time monitoring for builds, test results and deployments, giving teams quick feedback on the status of their code. Automated notifications (via email, Slack, or other messaging services) provide immediate insight into build failures or test results
    • Build logs, test reports and deployment outcomes are easily accessible, helping teams quickly debug and fix issues.
  • Security & Role Management

    • Jenkins offes a comprehensive security model, including role-based access control, plugin security, and API token management. Teams can assign different roles and permissions to users, ensuring the right people have access to specific jobs, configurations and resources.
  • Active Integration in DevOps & CI/CD Ecosystems

    • Jenkins has become a cornerstone of modern DevOps practices. Its integration capabilities with popular DevOps tools (Ansible, Terraform, Kubernetes, Docker) make it an essential part of CI/CD pipelines for automating software delivery, infrastructure management, and monitoring.

When to Choose Jenkins?

  • Large, distributed teams - Jenkins’ scalability and distributed builds are ideal for large organisations working on complex software projects

  • Custom CI/CD needs - If your project has custom requirements or complex pipelines, Jenkins’ extensive plugin ecosystem and customisability make it a strong candidate

  • Open-source preference - If your organisation prefers using open-source tools for flexibility and cost saving, Jenkins is a solid choice with no licence costs

  • Established infrastructure - If you already have an established CI/CD environment with specific tools and want to integrate them smoothly, Jenkins’ compatibility with a wide range of technologies is a huge plus.

Jenkins provides the flexibility, extensibility and scalability needed for automating CI/CD processes, making it a top choice for software developement teams.

Docker Compose Example

networks:
frontend:
external: true
services:
jenkins:
container_name: jenkins
image: jenkins/jenkins:lts
environment:
- "JENKINS_JAVA_OPTS=-Xmx2g -Xms2g"
ports:
- 8080:8080
- 50000:50000
volumes:
- ./jenkins_configuration:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
labels:
- traefik.enable=true
- traefik.http.routers.jenkins.rule=Host(`jenkins.<domain>`)
- traefik.http.routers.jenkins.entrypoints=https
- traefik.http.services.jenkins.loadbalancer.server.port=8080
- traefik.http.routers.jenkins.service=jenkins
- traefik.http.services.jenkins.loadbalancer.server.scheme=http
- traefik.http.routers.tls=true
- traefik.http.routers.jenkins.tls.certresolver=myresolver
- "--certificatesresolvers.myresolver.acme.dnschallenge=true"
- "--certificatesresolvers.myresolver.acme.dnschallenge.provider=cloudflare"
restart: unless-stopped
networks:
- frontend

Start Jenkins

Start Jenkins by running the following command within the folder / location where the docker compose file for Jenkins has been stored

docker compose up -d

Key Components of Docker Compose Configuration Explained

  • Image - Specifies the Jenkins server image and tag
  • Ports - Exposes Jenkins on specified
  • Volumes - For media files and custom templates
  • Environment - this sets the amount of RAM that Jenkins’ Java Virtual Machine(JVM) is allocated when running Jenkins. -Xmx (Maxiumum Heap Size), this limits the amount of RAM that can be allocated to the JVM. -Xms (Initial Heap Size) Determines the amount of RAM to the JVM on startup.
  • Labels - Used by Traefik to provide external access to the service, once the service all its dependancies have been started are "healthy" and Accessible, Public Service Name and what provider to use to check and obtain for an SSL Certificate

Volumes

  • Persistent Storage - Defined for PostgrSQL (Database) and Redis(redis)