As of the CloudBees CI 2.462.3.3 release, the jenkins-agent ConfigMap has been deprecated. The jenkins-agent ConfigMap will be removed from the Helm chart in late 2025.
|
This guide shows you how to migrate from the deprecated jenkins-agent
ConfigMap to agent-injection
.
If you have pod templates that leverage the jenkins-agent
ConfigMap, you need to migrate its configuration to the new agent-injection
option provided by the Kubernetes plugin as follows:
-
Select the Inject Jenkins agent in agent container option or add
agentInjection: true
to the pod template step or addagentInjection: true
in the declarative pipelines. -
Remove the volume mounting in the
jenkins-agent
ConfigMap and the associated command (the new option injects the required command and arguments automatically).
The following example uses agentInjection: true
in the pod template step.
// Build a Maven project using the standard image and Scripted syntax. // Rather than inline YAML, you could use: yaml: readTrusted('jenkins-pod.yaml') // Or, to avoid YAML: containers: [containerTemplate(name: 'maven', image: 'maven:3.6.3-jdk-8', command: 'sleep', args: 'infinity')] podTemplate( agentContainer: 'maven', agentInjection: true, yaml: ''' apiVersion: v1 kind: Pod spec: containers: - name: maven # In a real Jenkinsfile, it is recommended to pin to a specific version and use Dependabot or Renovate to bump it. image: maven:latest resources: requests: memory: "256Mi" limits: memory: "512Mi" command: - sleep args: - infinity securityContext: # maven runs as root by default, it is recommended or even mandatory in some environments (such as pod security admission "restricted") to run as a non-root user. runAsUser: 1000 ''') { retry(count: 2, conditions: [kubernetesAgent(), nonresumable()]) { node(POD_LABEL) { // some steps... } } }
The following example adds agentInjection: true
in a declarative pipeline and also uses agentContainer
. You can use this to provide the name of the container that will run the agent. This container must have a JDK installed and available in PATH.
pipeline { agent { kubernetes { agentInjection true agentContainer 'maven' yaml ''' apiVersion: v1 kind: Pod spec: containers: - name: maven # In a real Jenkinsfile, it is recommended to pin to a specific version and use Dependabot or Renovate to bump it. image: maven:latest resources: requests: memory: "256Mi" limits: memory: "512Mi" command: - sleep args: - infinity securityContext: # maven runs as root by default, it is recommended or even mandatory in some environments (such as pod security admission "restricted") to run as a non-root user. runAsUser: 1000 ''' } } stages { stage('Stage 1') { steps { // Some steps } } } }