Configure persistent Jenkins Agents

This section explains how to use JenkinsKubernetesAgent Custom Resource.

What is JenkinsKubernetesAgent

JenkinsKubernetesAgent is a CR (Custom Resource) you can create using Carthago Operator for Jenkins to have a persistent agent to run jobs on.

How to create JenkinsKubernetesAgent

You can create JenkinsKubernetesAgents in two ways:

  • Using carthago-op-jenkins-crs Helm chart.
  • By creating and applying its CR manifest directly.
Regardless of configuration method, the Jenkins Kubernetes Agent CRs must be created in the same namespace that their corresponding Jenkins instance is.
In the free plan, users can create one Jenkins Kubernetes Agent resource per Operator, and its name must be equal to seed-job-agent.

Below you can find instructions on how to create JenkinsKubernetesAgents.

How to create JenkinsKubernetesAgent using Helm chart

In the values.yaml file for carthago-op-jenkins-crs chart:

  1. Set .jenkinsKubernetesAgentEnabled to true. Otherwise, jenkinsKubernetesAgents section will be ignored.
  2. In jenkinsKubernetesAgents section, customize the Agent that is already there, or add another one.

Now all that’s left is to helm install or helm update the chart using the modified values.yaml file. For instructions on how to do that, visit Installation page

How to create JenkinsKubernetesAgent CR from its yaml manifest

Below you can find an example of a valid JenkinsKubernetesAgent CR manifest.

Edit its namespace and carthago.cloud/jenkins label to point to the namespace your Jenkins is deployed in and the name of your Jenkins, respectively.

Then kubectl apply it.

apiVersion: carthago.cloud/v1beta1
kind: JenkinsKubernetesAgent
metadata:
  name: seed-job-agent
  namespace: <jenkins-namespace>
  labels:
    carthago.cloud/jenkins: <jenkins-cr-name>
spec:
  podSpec:
    containers:
      - name: jnlp
        image: jenkins/inbound-agent:4.11.2-4
        imagePullPolicy: IfNotPresent

For description of all the fields you can configure in JenkinsKubernetesAgent, see Schema.

On agent labels in Jenkins

Operator sets labels of Agents created from JenkinsKubernetesAgent CRs to be equal to their name.

Because of that, if you’d like to run some of your pipelines on a particular agent, you can select it by specifying its name as a label in the node step of the pipelines.