Updated on 2025-01-03 GMT+08:00

Overview

Jenkins is an open-source automation server widely used for continuous integration (CI) and continuous delivery (CD). When your code library changes, Jenkins helps you automatically build, test, and deploy applications, improving development efficiency and product quality. Jenkins can be deployed in different environments. Each environment has their advantages. For details, see Table 1. In addition, Jenkins can be deployed on a single node or in a distributed mode.

  • Single-node deployment: Jenkins runs as an independent instance. All builds and operations are performed on the Jenkins master, which is responsible for job scheduling, system management, and execution of specific build jobs. All jobs are running on the same node, which may cause excessive consumption of system resources. In addition, as the project scale and the number of build jobs increase, single-node deployment may become a performance bottleneck. This deployment mode is suitable for small teams or individuals.
  • Distributed deployment: The Jenkins master is responsible for job scheduling and system management, and the Jenkins agents for executing specific build jobs. The Jenkins master receives build requests from users and distributes jobs to available Jenkins agents. Each Jenkins agent can be independently configured to support different OSs and build tools, providing flexible build environments and scalability. In addition, the separation of management and execution can effectively improve system performance and response speed. This mode is suitable for large-scale production environments, especially when there are a large number of build jobs or there are high requirements for concurrent builds.

This section uses distributed deployment as an example to describe how to deploy and use Jenkins in a CCE Autopilot cluster.

Table 1 Comparisons of environments where Jenkins will be deployed

Item

CCE Autopilot

CCE Standard/CCE Turbo

VMs

Physical Machines

Scenario

CI/CD and scenarios that have high requirements for automation management.

Large-scale distributed environment and CI/CD.

Small- and medium-sized projects, or scenarios where multiple teams or projects share one physical machine.

Scenarios that have high requirements for performance and hardware, require stable resources, and do not require frequent expansion.

Performance

High

High

Relatively low

High

Resource utilization

High

High

Relatively low

Low

O&M

Simple

Simple

Less complex

Complex

Scalability

Auto scaling in seconds

Auto scaling in minutes

Relatively poor

Poor

Availability

High

High

High

Relatively low

Isolation level

High

Relatively low

High

High

Precautions

CCE does not provide maintenance and support for Jenkins. The maintenance is provided by the developers.

Basic Concepts of Jenkins

  • Jenkins master: the core of the Jenkins system. It manages and coordinates all jobs. It can be regarded as a manager that does not directly execute jobs. Instead, it allocates jobs to other workers (Jenkins agents).

    The Jenkins master provides a web page for users to perform operations and view the task progress.

  • Jenkins agent: a pod or machine that Jenkins uses to execute jobs. Multiple Jenkins agents can be configured at the same time to share the load and improve job concurrency and efficiency.
  • Plugin: a component that extends the functionality of Jenkins. Jenkins allows users to install different plugins as needed to implement functions such as versioning, build tools, and deployment. In addition, plugins can integrate different tools and technologies, such as Kubernetes, Git, and Maven. The Kubernetes plugin is the key to information exchange between Jenkins and the cluster.
  • Pipeline: an automated workflow that connects multiple phases (such as build, test, and deployment) in the software development process to ensure that each step can be automatically executed in a certain sequence and based on certain rules. With the pipeline, you can deliver jobs to the Jenkins master and use the pipeline script to define the entire automation process. The Jenkins master executes the jobs based on the script.
  • Cloud: Various cloud environments, such as clusters, containers, and VMs, can be configured to flexibly use compute resources of external cloud platforms and implement dynamic management of Jenkins agents.
    Figure 1 Logical relationships between basic concepts

Solution Architecture

Figure 2 shows the steps for deploying Jenkins and Table 2 provides more details.

Figure 2 Flowchart
Table 2 Procedure

Step

Description

Image

Deploying the Jenkins Master in the Cluster

  • Install and deploy the Jenkins master in the CCE Autopilot cluster for managing jobs.
  • Use a browser to access the Jenkins master through the public IP address of the load balancer.

jenkins/jenkins:lts

NOTE:

jenkins/jenkins:lts indicates a Docker LTS image. The LTS version is a long-term release provided by Jenkins. It is relatively stable and will receive security updates and bug fixes for a longer time. It is suitable for production systems that require a stable environment. For more information, see LTS Release Line.

Configuring the Jenkins Agent

  • Install the Kubernetes plugin on the Jenkins web page.
  • Configure cluster information in the cloud to connect to the cluster.
  • Configure a pod template for dynamically creating Jenkins agent pods in the cloud.

The Jenkins agent requires three images:

  • jenkins/inbound-agent:latest: used to connect the Jenkins agent and Jenkins master to ensure continuous job execution.
  • maven:3.8.1-jdk-8: used to execute packing jobs in the pipeline.
  • gcr.io/kaniko-project/executor:v1.23.2-debug: used to build and push Docker images in the container.

Building and Executing a Pipeline on Jenkins

  • Compile a pipeline script on the Jenkins web page, define the automation process of the entire job, and compile the job into a language that can be understood by the Jenkins master.
  • The Jenkins master coordinates the execution process of the pipeline, dynamically creates Jenkins agents (in the form of pods) in the cluster through the Kubernetes plugin, and distributes jobs to Jenkins agents for processing. After the jobs are complete, Jenkins agents are automatically deleted.

In this example, the pipeline pulls code from the code repository, packs the code into an image, and pushes the image to the SWR image repository.

tomcat (This image needs to be pulled to SWR.)