Jenkins agent charm for K8s


This post is about jenkins-agent charm for k8s. The goal of this charm is to deploy jenkins agents (formerly called jenkins slave) to k8s.

The development of this charm led to the creation of this bug to make the operator framework allow customization of k8s deployment strategy. The default RollingUpdate strategy wasn’t compatible with the way agents are authenticated with jenkins.

To deploy the charm, follow the instructions below:

juju deploy cs:~jenkins-ci-charmers/jenkins-agent

When using the agents with juju-deployed jenkins, create a cross-model relation offer:

juju offer jenkins-agent:slave

And on your jenkins model, add the relation to it:

juju add-relation jenkins <your-controller>:admin/<your-microk8s-model>.jenkins-agent

In case your jenkins is not managed by juju, add a jenkins agent in your jenkins instance and configure the following on your model using the information provided by jenkins:

juju config jenkins-agents jenkins_master_url="<JENKINS-URL>" jenkins_agent_token="<TOKEN>"

The charm defaults to an image built using a Launchpad OCI Recipe and published to Docker Hub a customization of the docker image is required, clone the repository, modify the dockerfile, build it, save it to docker and export it to microk8s:

git clone -b master
cd charm-k8s-jenkins-agent
make build-image
docker save "${JENKINS_IMAGE}" > /var/tmp/"${JENKINS_IMAGE##*/}".tar
microk8s.ctr image import /var/tmp/"${JENKINS_IMAGE##*/}".tar

To use that modified image is as simple as changing the image configuration in juju:

juju config jenkins-agent image=<PATH-TO-YOUR-IMAGE>

There are still some improvements being made so we would welcome any feedback, suggestions, bug reports, or merge proposals. Special thanks to Facundo Batista (@facundo) and Tom Haddon(@mthaddon) for their feedback and suggestions during the development of this charm.