jenkins agent #1

Supports: kubernetes

Deploy this charm on Kubernetes with the CLI. Find out how by reading the docs.


This charm sets up a jenkins-agent in kubernetes.

Jenkins agent operator charm

This charm sets up a jenkins-agent in kubernetes.

Testing the docker image

juju deploy jenkins

Then go on the jenkins interface and create a permanent node called "jenkins-agent-k8s-test" manually for now.

export JENKINS_API_TOKEN=$(juju ssh 0 -- sudo cat /var/lib/jenkins/.admin_token)
export JENKINS_IMAGE="jenkins-agent-k8s:devel"
export JENKINS_IP=$(juju status --format json jenkins | jq -r '.machines."0"."ip-addresses"[0]')
make build-image
docker run --rm -ti --name jenkins-agent-test \
 -e JENKINS_API_USER=admin \
 -e JENKINS_URL="http://${JENKINS_IP}:8080" \
 -e JENKINS_HOSTNAME="jenkins-agent-test" "${JENKINS_IMAGE}"

Testing with microk8s

Install prerequisites

sudo snap install --channel 2.8/beta juju --classic
sudo snap install microk8s --classic
sudo snap install docker

# Start microk8s and enable needed modules
microk8s.enable registry dns storage
juju bootstrap microk8s micro

Build the jenkins-agent-k8s image

You need to have a jenkins charm deployed locally and have the following variables defined. See the "Testing the docker image" section.

  • JENKINS_API_TOKEN: the token for the admin user of your jenkins charm

  • JENKIN_IP: the ip of your jenkins charm instance

In this repository directory

export JENKINS_IMAGE="localhost:32000/jenkins-agent-k8s:devel"
export MODEL=jenkins-agent-k8s
make build-image
docker save "${JENKINS_IMAGE}" > /var/tmp/"${JENKINS_IMAGE##*/}".tar
microk8s.ctr image import /var/tmp/"${JENKINS_IMAGE##*/}".tar
juju add-model "${MODEL}"
juju model-config logging-config="<root>=DEBUG"
charmcraft build
juju deploy jenkins-agent.charm \
  --config "jenkins_agent_name=jenkins-agent-k8s-test" \
  --config "jenkins_api_token=${JENKINS_API_TOKEN:?}" \
  --config "jenkins_master_url=http://${JENKINS_IP:?}:8080" \
  --config "image=${JENKINS_IMAGE}"

Once everything is deployed, you can check the logs with

microk8s.kubectl -n "${MODEL}" logs -f --all-containers=true deployment/jenkins-agent


(string) The docker image to install. Required. Defaults to jenkins-agent image on dockerhub
(string) Comma-separated list of labels to be assigned to the agent in Jenkins. If not set it will default to the agents hardware identifier, e.g.: 'x86_64'
(string) Agent name as configured in Jenkins. Multiple names can be input by using `:` as a separator. Example: "agent-one:agent-two:agent-three"
(string) Agent token provided by Jenkins. Can be found in your Jenkins instance at ${JENKINS_URL}/computer/${AGENT_NAME}/. Multiple tokens can be input by using `:` as a separator matching the order of the agents in `jenkins_agent_name`. Example: "token-one:token-two:token-three"
(string) Configure the agent to use an explicit Jenkins master instead of using the jenkins-agent relation. This allows the agent to connect to a Jenkins instance not managed by Juju.