Jenkins as code, high availability and upgrades
Configuration as Code (JCasC)
Everything you'd click in "Manage Jenkins" expressed as YAML:
jenkins:
systemMessage: "Managed by JCasC — do not edit in the UI"
numExecutors: 0
securityRealm:
oic: # exact keys vary by OIDC plugin version
clientId: jenkins
clientSecret: "${OIDC_CLIENT_SECRET}" # injected from a secret
wellKnownOpenIDConfigurationUrl: https://sso.example.com/.well-known/openid-configuration
authorizationStrategy:
roleBased:
roles:
global:
- name: admin
permissions: ["Overall/Administer"]
entries: [{ group: "platform-admins" }]
- name: read
permissions: ["Overall/Read"]
entries: [{ group: "engineering" }]
clouds:
- kubernetes:
name: eks
namespace: jenkins-agents
jenkinsUrl: http://jenkins.jenkins.svc.cluster.local:8080
webSocket: true
containerCapStr: "50"
unclassified:
location:
url: https://jenkins.example.com/
globalLibraries:
libraries:
- name: platform-lib
defaultVersion: v2.3.0
retriever:
modernSCM:
scm:
git: { remote: "https://github.com/acme/jenkins-platform-lib.git" }
With JCasC + pinned plugins in an image + pipelines in Git + jobs generated by Job DSL or Organization Folders, the controller becomes reproducible: you can rebuild it from Git in minutes, and every change is reviewed.
Job DSL
Generates jobs from code instead of clicking:
multibranchPipelineJob('orders-api') {
branchSources {
github {
id('orders-api')
repoOwner('acme')
repository('orders-api')
scanCredentialsId('github-app')
}
}
orphanedItemStrategy { discardOldItems { numToKeep(20) } }
}
A seed job runs the DSL scripts from a repo.
Running Jenkins on Kubernetes
The official Helm chart deploys the controller as a StatefulSet with a PVC for JENKINS_HOME (EBS gp3), JCasC configured via ConfigMaps, an Ingress/ALB in front, and the Kubernetes cloud pre-configured for agents. Give the controller adequate requests/limits and JVM heap (-Xmx around 50–70% of the container memory, or -XX:MaxRAMPercentage).
High availability — the honest answer
Open-source Jenkins controllers are single-instance: JENKINS_HOME can't be shared by two active controllers. HA strategies:
- Fast recovery rather than active-active: controller as a Kubernetes StatefulSet (rescheduled automatically if the node dies, EBS volume reattached in the same AZ), or an EC2 Auto Scaling group of 1 with EFS/EBS — plus JCasC so a rebuild is quick.
- Backups of JENKINS_HOME (EBS snapshots via AWS Backup/DLM, or ThinBackup), tested restores.
- Split controllers by team or domain to reduce blast radius instead of one giant controller.
- CloudBees CI (commercial) offers HA/horizontal scaling features.
- Pipelines survive controller restarts thanks to durability (CPS checkpoints) — running builds resume where possible.
Upgrading safely
- Read the LTS changelog and upgrade guide; check plugin compatibility.
- Back up JENKINS_HOME (snapshot).
- Build a new controller image with the new LTS core and updated pinned plugins.
- Test on a staging controller with a copy of JENKINS_HOME or representative jobs.
- Roll out in a maintenance window ("Prepare for shutdown" lets running builds finish), keep the old image for rollback.