Customizing Jenkins
Adding or Customizing Jenkins Jobs
It is very common to add new Jenkins jobs or override Jenkins jobs provided in CloudOps for Kubernetes. CloudOps for Kubernetes includes a framework for importing custom Jenkins jobs into the Jenkins interface. The framework has several benefits, such as:
- It avoids the need to modify the CloudOps for Kubernetes
cloud-ops-kubernetes
Git repository, which can simplify the work required to apply future CloudOps for Kubernetes upgrades and patches. - It allows you to implement and configure your Jenkins jobs as code, ensuring that they are saved and changes are tracked in a Git repository that you control completely.
- It ensures that your Jenkins jobs will not be lost or disappear from the CloudOps for Kubernetes Jenkins instance when the Jenkins helm chart gets updated.
For more information about this recommended approach for adding new or overriding provided Jenkins jobs, see the CloudOps for Kubernetes Extensions Framework documentation.
CloudOps for Kubernetes Jenkins Architecture
A Jenkins server is deployed during the initial setup process. The implementation provided is based on the following community tools:
It is an option to customize and redeploy Jenkins if you require changes to meet your needs.
Configuring Jenkins
The configuration for Jenkins is split into the following:
- The
bootstrap/jenkins-helm-values.yaml.tmpl
file. This provides the majority of the configuration for Jenkins and includes:- The admin credentials to access Jenkins.
- Resource settings (RAM/CPU) for the Jenkins server. Resource settings for the agents are defined in files in
jenkins/agents/kubernetes
. - The plugins to install.
- The configuration for the Jenkins plugin Kubernetes.
- The persistent volume settings.
- The Groovy based init script to run:
- Creates the Jenkins Credential for the git server, based on the values set in
docker-compose.yml
for the bootstrap process. - Adds the ssh host key to the server, also from the
docker-compose.yml
file. - Creates and starts the bootstrap job inside Jenkins, where the job itself is defined in
cloudops-for-kubernetes/jenkins/jobs/bootstrap/bootstrap.groovy
.
- Creates the Jenkins Credential for the git server, based on the values set in
- The files in the
cloudops-for-kubernetes/jenkins/jobs
directory which define the Jenkins jobs. - The files in the
cloudops-for-kubernetes/jenkins/docker
directory which provides the container images that are used for the Jenkins agents. - The
jenkins-secrets
Kubernetes secret. This is normally created by the bootstrap process and it provides many settings used by the Jenkins jobs.
Updating the Container Images for the Jenkins Agents
Jenkins agents in CloudOps for Kubernetes use the container images in the jenkins/agents/docker
directory. If these container images need to be rebuilt, run the build-jenkins-agents
job.
Updating the Jenkins Jobs
To update the implementation of Jenkins jobs, push the code to the CloudOps for Kubernetes repository and branch set in the docker-compose.override.yml
file used during the bootstrap process.
If the configuration of the Jenkins job is changed by editing the jenkins/jobs/bootstrap/bootstrap.groovy
file, run the bootstrap
Jenkins job for the changes to be imported into the Jenkins server. The bootstrap
job updates any jobs where the configuration has changed.
Updating Jenkins
By default, Jenkins is deployed during the initial setup process.
If you need to update Jenkins or its plugins, test the changes first, ideally in an environment where errors will not impact development or production operations. You can perform tests to validate that the newer plugins do not have breaking changes either for the bootstrap container or any of the Jenkins jobs.
Defining Additional Plugins
The Jenkins deployment includes a number of plugins needed by the CloudOps for Kubernetes environment. These plugins are defined in the bootstrap/jenkins-helm-values.yaml.tmpl
file under the installPlugins
section.
If you need additional plugins to be installed as part of the deployment process, these should be added to the bootstrap/jenkins-helm-values.yaml.tmpl
file under the additionalPlugins
section. Defining custom plugins in this section will allow for easier merging of changes that may be made in future versions of CloudOps for Kubernetes.
Plugin Upgrade Testing Process
Deploy a new environment using the bootstrap container
Manually upgrade Jenkins and its plugins using the Jenkins web interface
Collect the names and versions of the Jenkins plugins
The easiest way to get the plugin names and versions is to run the following code in the Jenkins Script Console:
Jenkins.instance.pluginManager.plugins.each{ plugin -> println ("${plugin.getShortName()}: ${plugin.getVersion()}") }
Update the code to use the new version of Jenkins and the plugins
- The
bootstrap/jenkins-helm-values.yaml.tmpl
andjenkins.tf
files would have to be modified
- The
Deploy another new environment, using this newly updated code
Validate that all the Jenkins jobs in this new environment function as expected.
Update the Jenkins server version and plugins in the code of cloudops-for-kubernetes
Run the bootstrap container in "create" mode to apply the code changes
Remove the environments created for this task