Cloud Native 5 min read

Configuring Jenkins with a Chinese Mirror Using Docker

This guide explains how to set up a Jenkins instance with a domestic update mirror by customizing a Docker image, adjusting environment variables, copying certificates, and modifying update‑center URLs to improve plugin download speed in China.

DevOps Cloud Academy
DevOps Cloud Academy
DevOps Cloud Academy
Configuring Jenkins with a Chinese Mirror Using Docker

The article introduces a Docker‑based solution for speeding up Jenkins installation and plugin updates in China by using a pre‑configured image that points to a local update mirror, eliminating the need for manual mirror configuration steps.

Project analysis shows that the Dockerfile sets the Jenkins update center URL to https://updates.jenkins-zh.cn/update-center.json and configures a Tsinghua University mirror for plugin downloads.

Dockerfile snippet:

FROM jenkins/jenkins:lts
ENV JENKINS_UC https://updates.jenkins-zh.cn
ENV JENKINS_UC_DOWNLOAD https://mirrors.tuna.tsinghua.edu.cn/jenkins
ENV JENKINS_OPTS="-Dhudson.model.UpdateCenter.updateCenterUrl=https://updates.jenkins-zh.cn/update-center.json"
ENV JENKINS_OPTS="-Djenkins.install.runSetupWizard=false"
COPY init.groovy /usr/share/jenkins/ref/init.groovy.d/init.groovy
COPY hudson.model.UpdateCenter.xml /usr/share/jenkins/ref/hudson.model.UpdateCenter.xml
COPY mirror-adapter.crt /usr/share/jenkins/ref/mirror-adapter.crt

The last two COPY commands place the update‑center configuration and the custom certificate into $JENKINS_HOME . The init.groovy script (shown below) moves the certificate to the appropriate location inside the Jenkins war.

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
import hudson.init.InitMilestone;
import jenkins.model.Jenkins;

Thread.start {
  while (true) {
    Jenkins instance = Jenkins.getInstance();
    InitMilestone initLevel = instance.getInitLevel();
    Thread.sleep(1500L);
    println "Jenkins not ready when handle init config...";
    if (initLevel >= InitMilestone.PLUGINS_STARTED) {
      InputStream input = new FileInputStream("/usr/share/jenkins/ref/mirror-adapter.crt");
      FileOutputStream out = new FileOutputStream(System.getenv("JENKINS_HOME") + "/war/WEB-INF/update-center-rootCAs/mirror-adapter.crt");
      byte[] buf = new byte[1024];
      int count = -1;
      while ((count = input.read(buf)) > 0) {
        out.write(buf, 0, count);
      }
      println "Jenkins init ready...";
      break;
    }
  }
}

Configuration steps

Step 1: Replace the certificate – navigate to $JENKINS_HOME/war/WEB-INF/update-center-rootCAs , remove existing certificates, and download the new mirror-adapter.crt from the GitHub repository.

# Enter certificate directory
cd $JENKINS_HOME/war/WEB-INF/update-center-rootCAs
# Clean current certificates
rm -fr jenkins-update-center-root-ca jenkins-update-center-root-ca.txt
# Copy new certificate
curl 'https://raw.githubusercontent.com/jenkins-zh/docker-zh/master/mirror-adapter.crt' -o $JENKINS_HOME/war/WEB-INF/update-center-rootCAs/mirror-adapter.crt

Step 2: Change the update source address – modify Jenkins’ update center URL to point to https://updates.jenkins-zh.cn/update-center.json either via the Docker environment variable or through the Jenkins UI.

After applying these changes and restarting Jenkins, plugin downloads and updates are served from the domestic mirror, resulting in significantly faster installation times.

Dockerci/cdconfigurationdevopsJenkinsmirror
DevOps Cloud Academy
Written by

DevOps Cloud Academy

Exploring industry DevOps practices and technical expertise.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.