1. How to Deploy Jenkins
To make the tests below easier, let me first introduce two ways to deploy Jenkins. Here I use the shaowenchen/jenkins:2.277.4 image. In a production environment, you should replace it with the official jenkins/jenkins image or your own custom image.
1.1 Running with docker-compose
The docker-compose.yaml file
version: '3'
services:
jenkins:
image: shaowenchen/jenkins:2.277.4
container_name: jenkins
restart: always
network_mode: "bridge"
environment:
- JAVA_OPTS="-Xms1Gi -Xmx4Gi"
ports:
- 8080:8080
- 50000:50000
- 2222:2222
environment:
TZ: Asia/Shanghai
volumes:
- /Volumes/Data/jenkins_home:/var/jenkins_home
Create a local directory /Volumes/Data/jenkins_home to store Jenkins data; port 8080 is for web page access, port 50000 is for connecting Agents, and port 2222 is for managing Jenkins over SSH.
| |
After running the command, you can find the initial password for the admin user in the scrolling logs. This is the deployment method I use locally.
1.2 Deploying on Kubernetes
- Create the configuration file
The values.yaml file
master:
image: "shaowenchen/jenkins"
tag: "2.277.4"
serviceType: NodePort
nodePort: 38080
adminPassword: password
imagePullPolicy: "Always"
resources:
requests:
cpu: "1"
memory: "2Gi"
limits:
cpu: "4"
memory: "4Gi"
installPlugins: []
persistence:
enabled: true
size: "10Gi"
In the installPlugins configuration item, you can specify the list of plugins to install when Jenkins starts.
- Add the Helm repository
| |
- Install Jenkins
| |
- Uninstall Jenkins
| |
2. Managing Jenkins with the CLI
Here I introduce two ways to manage Jenkins from the command line. Jenkins supports CLI management over both SSH and HTTP.
2.1 The First Way: over SSH
- Generate an ssh-key key pair
| |
- View the public key
| |
- Add the SSH public key in Jenkins
Jenkins -> User -> Settings -> SSH Public Keys -> Save

- Specify the SSHD port
Manage Jenkins -> Global Security Configuration -> SSH Server, specify the port -> Save

Here port 2222 is used; you can configure it according to your own needs.
- Manage Jenkins remotely over SSH
Here the default Jenkins administrator account admin is used
| |
2.2 The Second Way: via the Client
http://localhost:8080/ is the Jenkins page, and at the page address http://localhost:8080/jnlpJars/jenkins-cli.jar you can download the Jenkins client tool.
The CLI tool may be incompatible across different Jenkins versions, so it is recommended to download the client tool for the current environment. Here xxx refers to the admin user’s page login password, and it can also be a user-generated API Token.
| |
The CLI tool basically covers pipeline jobs, nodes, credentials, and Jenkins management functions, which can meet the needs of most operations scenarios.
3. Customizing the Jenkins Version
3.1 Downloading the custom-war-packager-cli Tool
Visit https://repo.jenkins-ci.org/list/releases/io/jenkins/tools/custom-war-packager/custom-war-packager-cli/ and download the latest version of the custom-war-packager tool. Note that you should choose the package with with-dependencies.
The version I downloaded here is 2.0-alpha-5
| |
3.2 Customizing Jenkins
For the specific configuration, refer to: https://github.com/jenkinsci/custom-war-packager/ . Below is a test configuration of mine:
The config.yaml file
| |
There are two main points to focus on here: buildSettings and plugins. You can also specify a CasC file.
- buildSettings, which specifies the build artifact. What it means here is to package the
shaowenchen/jenkins:2.277.4image based on thejenkins/jenkins:2.277.4image. - plugins, which specifies the list of plugins to download.
Now let’s compile the image:
| |
This produces a customized Jenkins image. Run shaowenchen/jenkins:2.277.4 directly, and the configuration-as-code plugin is already built in with no installation needed.
4. How to Add New Plugins to Jenkins
4.1 The First Way: Search on the Page or Upload Offline
Open the Jenkins plugin management page and search online directly.

Then, click install.

The official default plugin source is https://updates.jenkins.io/update-center.json . If access is not fast enough, you can change it to another source. In Plugin Management -> Advanced -> Update Site, replace the URL with https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json .
Another way is offline upload, but Jenkins plugins have dependencies on each other, so an offline upload has to upload all the dependency packages, which is rather troublesome and not recommended. In an offline environment, you can collect the list of dependent plugins into a text file, then use plugin-installation-manager-tool to download them, and provide the plugin source through Nginx.
4.2 The Second Way: via the CLI Tool
As mentioned earlier, Jenkins can be managed through the CLI tool, which includes plugin management.
- Use the client’s install-plugin subcommand to install the specified plugin
| |
- Restart Jenkins for it to take effect
| |
But this approach does not solve the plugin dependency conflict problem. That is, when new plugin A depends on the latest version of plugin B, plugin B will not be updated automatically, which makes new plugin A unavailable. And if you upgrade B directly, it may in turn make other plugins that depend on B unavailable. Here you need to determine the version dependencies.
4.3 The Third Way: via custom-war-packager
From what we learned earlier, we know that we only need to add new plugins to the config.yaml file.
| |
Then recompile and repackage, but you will find that the plugin still does not work properly, again because the plugin dependency conflict problem is not solved.

According to the page prompt, we need to upgrade a dependency package, Snakeyaml API Plugin, from 1.26.4 to 1.27.0. In that case, you just need to write it explicitly in the config.yaml file.
| |
After compiling and building again, Jenkins runs normally.
5. Summary
As an orchestration engine that has existed for more than ten years, Jenkins has a significant first-mover advantage, and its plugin ecosystem and surrounding tooling are very mature.
This article mainly introduces a few features that are not commonly used but are useful:
- The Jenkins CLI tool. Managing Jenkins through a command-line tool is an interesting area, and it makes automated integration very convenient.
- custom-war-packager for custom images. It packages Jenkins dependencies such as plugins and configuration into a single whole for deployment, which lets you manage the runtime environment well.
However, neither of these two approaches adapts well in terms of plugin compatibility, and both require manual intervention.
