# Migrate from jenkins-agent ConfigMap to agent-injection

Migrate from `jenkins-agent` ConfigMap to `agent-injection`
===========================================================

The `jenkins-agent` ConfigMap was removed from the Helm chart in CloudBees CI 2.568.2.37664 (deprecated as of 2.462.3.3).

If your pod templates use the `jenkins-agent` ConfigMap, you must migrate the configuration to the `agent-injection` option provided by the [Kubernetes plugin](/plugins/ci/kubernetes).

1.  To inject the agent, use one of the following methods:
    
    *   Select **Inject Jenkins agent in agent container**.
        
    *   Add `agentInjection: true` to the `podTemplate` step.
        
    *   Specify `agentInjection true` in Declarative Pipelines.
        
    
2.  Remove volume mounting of the `jenkins-agent` ConfigMap and the associated command; the injection method you selected handles this automatically.
    

[](#_scripted_pipeline_example)Scripted Pipeline example
--------------------------------------------------------

The following example uses `agentInjection: true` in the `podTemplate` 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...
            }
        }
    }

[](#_declarative_pipeline_example)Declarative Pipeline example
--------------------------------------------------------------

The following example uses `agentInjection true` in a Declarative Pipeline with `agentContainer` to specify the container that runs the agent.

The container specified by `agentContainer` 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
          }
        }
      }
    }