jenkins
by Jenkins
Jenkins - Build great things at any scale! As the leading open source automation server, Jenkins provides over 2000 plugins to support building, deploying and automating any project.
About this chart
Jenkins
Jenkins is the leading open source automation server, Jenkins provides over 2000 plugins to support building, deploying and automating any project.
This chart installs a Jenkins server which spawns agents on Kubernetes utilizing the Jenkins Kubernetes plugin.
Inspired by the awesome work of Carlos Sanchez.
Get Repository Info
helm repo add jenkins https://charts.jenkins.io
helm repo update
See helm repo for command documentation.
Install Chart
helm install [RELEASE_NAME] jenkins/jenkins [flags]
Since version 5.6.0 the chart is available as an OCI image and can be installed using:
helm install [RELEASE_NAME] oci://ghcr.io/jenkinsci/helm-charts/jenkins [flags]
See configuration below.
See helm install for command documentation.
Uninstall Chart
# Helm 3
$ helm uninstall [RELEASE_NAME]
This removes all the Kubernetes components associated with the chart and deletes the release.
See helm uninstall for command documentation.
Upgrade Chart
# Helm 3
$ helm upgrade [RELEASE_NAME] jenkins/jenkins [flags]
See helm upgrade for command documentation.
Visit the chart's CHANGELOG to view the chart's release history. For migration between major version check migration guide.
Building weekly releases
The default charts target Long-Term-Support (LTS) releases of Jenkins.
To use other versions the easiest way is to update the image tag to the version you want.
You can also rebuild the chart if you want the appVersion field to match.
Configuration
See Customizing the Chart Before Installing. To see all configurable options with detailed comments, visit the chart's values.yaml, or run these configuration commands:
# Helm 3
$ helm show values jenkins/jenkins
For a summary of all configurable options, see VALUES.md.
Configure Kubernetes Cloud Traits
Set controller.cloudTraits to add traits to the chart-generated Kubernetes cloud. Additional clouds inherit this list; set additionalClouds.<name>.controller.cloudTraits to override it (including with [] to disable inherited traits).
controller:
cloudTraits:
- ephemeralContainer
additionalClouds:
remote-cloud:
kubernetesURL: https://api.remote-cloud.com
controller:
cloudTraits:
- ephemeralContainer
Configure Security Realm and Authorization Strategy
This chart configured a securityRealm and authorizationStrategy as shown below:
controller:
JCasC:
securityRealm: |-
local:
allowsSignup: false
enableCaptcha: false
users:
- id: "${chart-admin-username}"
name: "Jenkins Admin"
password: "${chart-admin-password}"
authorizationStrategy: |-
loggedInUsersCanDoAnything:
allowAnonymousRead: false
With the configuration above there is only a single user. This is fine for getting started quickly, but it needs to be adjusted for any serious environment.
So you should adjust this to suite your needs. That could be using LDAP / OIDC / .. as authorization strategy and use globalMatrix as authorization strategy to configure more fine-grained permissions.
Consider using a custom image
This chart allows the user to specify plugins which should be installed. However, for production use cases one should consider to build a custom Jenkins image which has all required plugins pre-installed. This way you can be sure which plugins Jenkins is using when starting up and you avoid trouble in case of connectivity issues to the Jenkins update site.
The Docker repository for the Jenkins image contains documentation how to do it.
Here is an example how that can be done:
FROM jenkins/jenkins:lts
RUN jenkins-plugin-cli --plugins kubernetes workflow-aggregator git configuration-as-code
NOTE: If you want a reproducible build then you should specify a non-floating tag for the image jenkins/jenkins:2.249.3 and specify plugin versions.
Once you built the image and pushed it to your registry you can specify it in your values file like this:
controller:
image: "registry/my-jenkins"
tag: "v1.2.3"
installPlugins: false
Notice: installPlugins is set to false to disable plugin download. In this case, the image registry/my-jenkins:v1.2.3 must have the plugins specified as default value for the controller.installPlugins directive to ensure that the configuration side-car system works as expected.
In case you are using a private registry you can use 'imagePullSecretName' to specify the name of the secret to use when pulling the image:
controller:
image: "registry/my-jenkins"
tag: "v1.2.3"
imagePullSecretName: registry-secret
installPlugins: false
External URL Configuration
If you are using the ingress definitions provided by this chart via the controller.ingress block the configured hostname will be the ingress hostname starting with https:// or http:// depending on the tls configuration.
The Protocol can be overwritten by specifying controller.jenkinsUrlProtocol.
If you are not using the provided ingress you can specify controller.jenkinsUrl to change the URL definition.
Configuration as Code
Jenkins Configuration as Code (JCasC) is now a standard component in the Jenkins project.
To allow JCasC's configuration from the helm values, the plugin configuration-as-code must be installed in the Jenkins Controller's Docker image (which is the case by default as specified by the default value of the directive controller.installPlugins).
JCasc configuration is passed through Helm values under the key controller.JCasC.
The section "Jenkins Configuration as Code (JCasC)" of the page "VALUES_SUMMARY.md" lists all the possible directives.
In particular, you may specify custom JCasC scripts by adding sub-key under the controller.JCasC.configScripts for each configuration area where each corresponds to a plugin or section of the UI.
The sub-keys (prior to | character) are only labels used to give the section a meaningful name.
The only restriction is they must conform to RFC 1123 definition of a DNS label, so they may only contain lowercase letters, numbers, and hyphens.
Each key will become the name of a configuration yaml file on the controller in /var/jenkins_home/casc_configs (by default) and will be processed by the Configuration as Code Plugin during Jenkins startup.
The lines after each | become the content of the configuration yaml file.
The first line after this is a JCasC root element, e.g. jenkins, credentials, etc.
Best reference is the Documentation link here: https://<jenkins_url>/configuration-as-code.
The example below sets custom systemMessage:
controller:
JCasC:
configScripts:
welcome-message: |
jenkins:
systemMessage: Welcome to our CI\CD server.
More complex example that creates ldap settings:
controller:
JCasC:
configScripts:
ldap-settings: |
jenkins:
securityRealm:
ldap:
configurations:
- server: ldap.acme.com
rootDN: dc=acme,dc=uk
managerPasswordSecret: ${LDAP_PASSWORD}
groupMembershipStrategy:
fromUserRecord:
attributeName: "memberOf"
Keep in mind that default configuration file already contains some values that you won't be able to override under configScripts section.
For example, you can not configure Jenkins URL and System Admin email address like this because of conflicting configuration error.
Incorrect:
controller:
JCasC:
configScripts:
jenkins-url: |
unclassified:
location:
url: https://example.com/jenkins
adminAddress: [email protected]
Correct:
controller:
jenkinsUrl: https://example.com/jenkins
jenkinsAdminEmail: [email protected]
Further JCasC examples can be found in the configuration-as-code repository.
Breaking out large Config as Code scripts
Jenkins Config as Code scripts can become quite large, and maintaining all of your scripts within one yaml file can be difficult. The Config as Code plugin itself suggests updating the CASC_JENKINS_CONFIG environment variable to be a comma separated list of paths for the plugin to traverse, picking up the yaml files as needed.
However, under the Jenkins helm chart, this CASC_JENKINS_CONFIG value is maintained through the templates. A better solution is to split your controller.JCasC.configScripts into separate values files, and provide each file during the helm install.
For example, you can have a values file (e.g values_main.yaml) that defines the values described in the VALUES_SUMMARY.md for your Jenkins configuration:
jenkins:
controller:
jenkinsUrlProtocol: https
installPlugins: false
...
In a second file (e.g values_jenkins_casc.yaml), you can define a section of your config scripts:
jenkins:
controller:
JCasC:
configScripts:
jenkinsCasc: |
jenkins:
disableRememberMe: false
mode: NORMAL
...
And keep extending your config scripts by creating more files (so not all config scripts are located in one yaml file for better maintenance):
values_jenkins_unclassified.yaml
jenkins:
controller:
JCasC:
configScripts:
unclassifiedCasc: |
unclassified:
...
When installing, you provide all relevant yaml files (e.g helm install -f values_main.yaml -f values_jenkins_casc.yaml -f values_jenkins_unclassified.yaml ...). Instead of updating the CASC_JENKINS_CONFIG environment variable to include multiple paths, multiple CasC yaml files will be created in the same path var/jenkins_home/casc_configs.
Config as Code With or Without Auto-Reload
Config as Code changes (to controller.JCasC.configScripts) can either force a new pod to be created and only be applied at next startup, or can be auto-reloaded on-the-fly.
If you set controller.sidecars.configAutoReload.enabled to true, a second, auxiliary container will be installed into the Jenkins controller pod, known as a "sidecar".
This watches for changes to configScripts, copies the content onto the Jenkins file-system and issues a POST to http://<jenkins_url>/reload-configuration-as-code with a pre-shared key.
You can monitor this sidecar's logs using command kubectl logs <controller_pod> -c config-reload -f.
If you want to enable auto-reload then you also need to configure rbac as the container which triggers the reload needs to watch the config maps:
controller:
sidecars:
configAutoReload:
enabled: true
rbac:
create: true
Allow Limited HTML Markup in User-Submitted Text
Some third-party systems (e.g. GitHub) use HTML-formatted data in their payload sent to a Jenkins webhook (e.g. URL of a pull-request being built).
To display such data as processed HTML instead of raw text set controller.enableRawHtmlMarkupFormatter to true.
This option requires installation of the OWASP Markup Formatter Plugin (antisamy-markup-formatter).
This plugin is not installed by default but may be added to controller.additionalPlugins.
Change max connections to Kubernetes API
When using agents with containers other than JNLP, The kubernetes plugin will communicate with those containers using the Kubernetes API. this changes the maximum concurrent connections
agent:
maxRequestsPerHostStr: "32"
This will change the configuration of the kubernetes "cloud" (as called by jenkins) that is created automatically as part of this helm chart.
Change container cleanup timeout API
For tasks that use very large images, this timeout can be increased to avoid early termination of the task while the Kubernetes pod is still deploying.
agent:
retentionTimeout: "32"
This will change the configuration of the kubernetes "cloud" (as called by jenki
Deploy jenkins with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has jenkins on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartjenkins is pinned at v5.14.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply