The following plugin provides functionality available through Pipeline-compatible steps. Read more about how to integrate steps into your Pipeline in the Steps section of the Pipeline Syntax page.

For a list of other such plugins, see the Pipeline Steps Reference page.

Kubernetes plugin

container: Run build steps in a container

Selects a container of the agent pod so that all shell steps are executed in that container.
  • name
    • Type: String
  • shell (optional)

    Specifies a shell which will run inside the container and process requests from Jenkins to run executables, set environment variables, and similar infrastructure.

    This does not affect the shell used to run user code, such as sh steps. To run your scripts with a specific shell on Linux, use an interpreter line:

    sh '''#!/bin/bash
    for x in {0..9}; do echo x; done
    '''

    or just use a subprocess and an externally versioned script:

    sh 'bash ci.sh'

    On Windows, choose between the bat or powershell steps.

    For a pod running on Linux, defaults to sh, which should be in $PATH; for a pod running on Windows, defaults to cmd, which should be in %Path%. Should not generally be overridden.

    • Type: String

podTemplate: Define a podTemplate to use in the kubernetes plugin

Defines a Kubernetes pod template that can be used to create nodes.

Example:

podTemplate(...) {
    node(POD_LABEL) {
        // some steps
    }
}
  • activeDeadlineSeconds (optional)
    • Type: int
  • annotations (optional)
      Array / List of Nested Object
    • key
      The annotation key.
      • Type: String
    • value
      The annotation value.
      • Type: String
  • cloud (optional)
    The Kubernetes cloud to use to schedule the pod.
    If unset, the first available Kubernetes cloud will be used.
    • Type: String
  • containers (optional)
      Array / List of Nested Object
    • name
      The name for the container to be run. One container is automatically created with name jnlp, and runs the Jenkins JNLP agent service. In order to replace the default JNLP agent, the name of the container with the custom JNLP image must be jnlp.
      • Type: String
    • image
      Docker image ID for a jenkins JNLP agent. This image is responsible to run a jenkins jnlp bootstrap agent and connect to Jenkins controller. Secret key and agent name as well as jenkins callback URL are passed as argument as expected by hudson.remoting.jnlp.Main.
      • Type: String
    • alwaysPullImage (optional)
      If ticked, the latest version of the image will be pulled every time it is used. See Images - Kubernetes for the default Kubernetes behaviour.
      • Type: boolean
    • args (optional)

      Arguments to pass to the command.

      ${computer.jnlpmac} and ${computer.name} are replaced with the agent secret and name respectively.

      For Windows containers the args Start-Sleep 999999 are reasonable choices to go with powershell.

      • Type: String
    • command (optional)

      Override the image entrypoint with a different one.

      For Windows containers powershell is a good default.

      • Type: String
    • envVars (optional)
      The environment variables to pass to the container.
        Array / List of Nested Choice of Objects
      • containerEnvVar
        • key
          The environment variable key.
          • Type: String
        • value
          The environment variable value.
          • Type: String
      • envVar
        • key
          The environment variable key.
          • Type: String
        • value
          The environment variable value.
          • Type: String
      • podEnvVar
        • key
          The environment variable key.
          • Type: String
        • value
          The environment variable value.
          • Type: String
      • secretEnvVar
        • key
          The environment variable key.
          • Type: String
        • secretName
          Name of secret to lookup from Kubernetes.
          • Type: String
        • secretKey
          Key of secret to lookup from Kubernetes.
          • Type: String
        • optional
          Whether this secret is optional.
          • Type: boolean
    • livenessProbe (optional)
        Nested Object
      • execArgs
        Command executed by the liveness probe.
        • Type: String
      • timeoutSeconds
        Number of seconds after which the probe times out. Defaults to 1 second. Minimum value is 1.
        • Type: int
      • initialDelaySeconds
        Number of seconds after the container has started before liveness or readiness probes are initiated. Defaults to 0 seconds. Minimum value is 0.
        • Type: int
      • failureThreshold

        When a Pod starts and the probe fails, Kubernetes will try failureThreshold times before giving up.
        Giving up in case of liveness probe means restarting the container.
        In case of readiness probe the Pod will be marked Unready. Defaults to 3. Minimum value is 1.

        • Type: int
      • periodSeconds

        How often (in seconds) to perform the probe. Default to 10 seconds. Minimum value is 1.

        • Type: int
      • successThreshold
        Minimum consecutive successes for the probe to be considered successful after having failed. Defaults to 1. Must be 1 for liveness. Minimum value is 1.
        • Type: int
    • ports (optional)
        Array / List of Nested Object
      • name (optional)
        The name of the port
        • Type: String
      • containerPort (optional)
        Port to expose into the pod
        • Type: int
      • hostPort (optional)
        Port to expose onto the host
        • Type: int
    • privileged (optional)
      Flag to mark the container as privileged.
      • Type: boolean
    • resourceLimitCpu (optional)
      Kubernetes Resources Limit of CPU This value can be set to control the CPU resource limit passed when creating the Jenkins agent Docker container in Kubernetes. Unlike a resource request, this is the upper limit of resources used by your Jenkins Agent container. When left blank, the defaults of your Kubernetes cluster will be used. For more info, see the Kubernetes docs. e.g. `500m`.
      • Type: String
    • resourceLimitEphemeralStorage (optional)
      • Type: String
    • resourceLimitMemory (optional)
      Kubernetes Resources Limit of Memory This value can be set to control the memory resource limit passed when creating the Jenkins agent Docker container in Kubernetes. Unlike a resource request, this is the upper limit of resources used by your Jenkins Agent container. When left blank, the defaults of your Kubernetes cluster will be used. For more info, see the Kubernetes docs. e.g. `250Mi`.
      • Type: String
    • resourceRequestCpu (optional)
      Kubernetes Resources Request of CPU This value can be set to control the CPU resources requested when creating the Jenkins agent Docker container in Kubernetes. When left blank, the defaults of your Kubernetes cluster will be used. For more info, see the Kubernetes docs. e.g. `500m`.
      • Type: String
    • resourceRequestEphemeralStorage (optional)
      • Type: String
    • resourceRequestMemory (optional)
      Kubernetes Resources Request of Memory This value can be set to control the memory resources requested when creating the Jenkins agent Docker container in Kubernetes. When left blank, the defaults of your Kubernetes cluster will be used. For more info, see the Kubernetes docs. e.g. `250Mi`.
      • Type: String
    • runAsGroup (optional)
      Specify the gid to run as.
      • Type: String
    • runAsUser (optional)
      Specify the uid to run as.
      • Type: String
    • shell (optional)
      • Type: String
    • ttyEnabled (optional)
      Whether this container should allocate a TTY for itself.
      • Type: boolean
    • workingDir (optional)
      Path to the root of the workspace from the view point of this container, such as /home/jenkins/agent.
      • Type: String
  • envVars (optional)
      Array / List of Nested Choice of Objects
    • containerEnvVar
      • key
        The environment variable key.
        • Type: String
      • value
        The environment variable value.
        • Type: String
    • envVar
      • key
        The environment variable key.
        • Type: String
      • value
        The environment variable value.
        • Type: String
    • podEnvVar
      • key
        The environment variable key.
        • Type: String
      • value
        The environment variable value.
        • Type: String
    • secretEnvVar
      • key
        The environment variable key.
        • Type: String
      • secretName
        Name of secret to lookup from Kubernetes.
        • Type: String
      • secretKey
        Key of secret to lookup from Kubernetes.
        • Type: String
      • optional
        Whether this secret is optional.
        • Type: boolean
  • hostNetwork (optional)
    • Type: boolean
  • idleMinutes (optional)
    • Type: int
  • imagePullSecrets (optional)
    • Type: Array / List of String
  • inheritFrom (optional)
    • Type: String
  • instanceCap (optional)
    • Type: int
  • label (optional)
    Jenkins node label to bind. If left blank, one will be generated for you, and inside the step it will be bound to the variable POD_LABEL so you can use this as the argument to the node step.
    Example:
            podTemplate(...) {
                node(POD_LABEL) {
                    // some steps
                }
            }
        
    • Type: String
  • name (optional)
    • Type: String
  • namespace (optional)
    • Type: String
  • nodeSelector (optional)
    • Type: String
  • nodeUsageMode (optional)
    • Type: String
  • podRetention (optional)
      Nested Choice of Objects
    • always
      • default
        • never
          • onFailure
          • runAsGroup (optional)
            • Type: String
          • runAsUser (optional)
            • Type: String
          • schedulerName (optional)
            • Type: String
          • serviceAccount (optional)
            • Type: String
          • showRawYaml (optional)
            • Type: boolean
          • slaveConnectTimeout (optional)
            • Type: int
          • supplementalGroups (optional)
            • Type: String
          • volumes (optional)
              Array / List of Nested Choice of Objects
            • configMapVolume
              • mountPath
                Path to mount this volume inside the pod.
                • Type: String
              • configMapName
                The name of the Kubernetes Config Map to mount into the pod.
                • Type: String
              • optional
                Whether this configmap needs to exist.
                • Type: boolean
              • subPath (optional)
                SubPath to mount this volume inside the pod.
                • Type: String
            • dynamicPVC
              • accessModes (optional)
                A PersistentVolume can be mounted on a host in any way supported by the resource provider. Providers will have different capabilities and each PV’s access modes are set to the specific modes supported by that particular volume. For example, NFS can support multiple read/write clients, but a specific NFS PV might be exported on the server as read-only. Each PV gets its own set of access modes describing that specific PV’s capabilities. Defaults to ReadWriteOnce.
                • Type: String
              • mountPath (optional)
                Path to mount this volume inside the pod.
                • Type: String
              • requestsSize (optional)
                Claims, like pods, can request specific quantities of a resource. In this case, the request is for storage. The same resource model applies to both volumes and claims. Defaults to 10Gi.
                • Type: String
              • storageClassName (optional)
                A StorageClass provides a way for administrators to describe the “classes” of storage they offer. Different classes might map to quality-of-service levels, or to backup policies, or to arbitrary policies determined by the cluster administrators. Kubernetes itself is unopinionated about what classes represent. This concept is sometimes called “profiles” in other storage systems.
                • Type: String
            • emptyDirVolume
              • mountPath
                Path to mount this volume inside the pod.
                • Type: String
              • memory
                Flag for in-memory volume.
                • Type: boolean
            • hostPathVolume
              • hostPath
                File or directory on the host node's filesystem to mount into the pod.
                • Type: String
              • mountPath
                Path to mount this volume inside the pod.
                • Type: String
            • nfsVolume
              • serverAddress
                NFS Server Address.
                • Type: String
              • serverPath
                NFS Server Path.
                • Type: String
              • readOnly
                • Type: boolean
              • mountPath
                Path to mount this volume inside the pod.
                • Type: String
            • persistentVolumeClaim
              • mountPath
                Path to mount this volume inside the pod.
                • Type: String
              • claimName
                The claim name.
                • Type: String
              • readOnly
                Flag for read-only volume.
                • Type: boolean
            • secretVolume
              • mountPath
                Path to mount this volume inside the pod.
                • Type: String
              • secretName
                The name of the Kubernetes Secret to mount into the pod.
                • Type: String
              • defaultMode
                The file permissions for the secret volume. Does not support Octal notation.
                • Type: String
              • optional
                Whether the secret needs to exist.
                • Type: boolean
          • workingDir (optional)
            • Type: String
          • workspaceVolume (optional)
              Nested Choice of Objects
            • dynamicPVC
              • accessModes (optional)
                A PersistentVolume can be mounted on a host in any way supported by the resource provider. Providers will have different capabilities and each PV’s access modes are set to the specific modes supported by that particular volume. For example, NFS can support multiple read/write clients, but a specific NFS PV might be exported on the server as read-only. Each PV gets its own set of access modes describing that specific PV’s capabilities. Defaults to ReadWriteOnce.
                • Type: String
              • requestsSize (optional)
                Claims, like pods, can request specific quantities of a resource. In this case, the request is for storage. The same resource model applies to both volumes and claims. Defaults to 10Gi.
                • Type: String
              • storageClassName (optional)
                A StorageClass provides a way for administrators to describe the “classes” of storage they offer. Different classes might map to quality-of-service levels, or to backup policies, or to arbitrary policies determined by the cluster administrators. Kubernetes itself is unopinionated about what classes represent. This concept is sometimes called “profiles” in other storage systems.
                • Type: String
            • emptyDirWorkspaceVolume
              • memory
                Flag for in-memory volume.
                • Type: boolean
            • hostPathWorkspaceVolume
              • hostPath
                File or directory on the host node's filesystem to mount into the pod.
                • Type: String
            • nfsWorkspaceVolume
              • serverAddress
                NFS Server Address.
                • Type: String
              • serverPath
                NFS Server Path.
                • Type: String
              • readOnly
                • Type: boolean
            • persistentVolumeClaimWorkspaceVolume
              • claimName
                The claim name.
                • Type: String
              • readOnly
                Flag for read-only volume.
                • Type: boolean
          • yaml (optional)
            • Type: String
          • yamlMergeStrategy (optional)
              Nested Choice of Objects
            • merge
              • override

              kubeconfig: Setup Kubernetes CLI (kubectl)

              Configure Kubernetes client (kubectl) so it can be used in the build to run Kubernetes commands
              • serverUrl
                URL of the Kubernetes API endpoint. If not set the connection options will be autoconfigured from service account or kube config file.
                • Type: String
              • credentialsId
                • Type: String
              • caCertificate
                The base64 encoded certificate of the certificate authority (CA). It is used to verify the server certificate.

                Leaving this field empty will skip the certificate verification.

                • Type: String

              containerLog: Get container log from Kubernetes

              • name
                Name of the container, as specified in containerTemplate.
                • Type: String
              • limitBytes (optional)
                If set, the number of bytes to read from the server before terminating the log output. This may not display a complete final line of logging, and may return slightly more or slightly less than the specified limit.
                • Type: int
              • returnLog (optional)
                Return the container log. If not checked, the log will be printed to the build log.
                • Type: boolean
              • sinceSeconds (optional)
                A relative time in seconds before the current time from which to show logs. If this value precedes the time a pod was started, only logs since the pod start will be returned. If this value is in the future, no logs will be returned.
                • Type: int
              • tailingLines (optional)
                If set, the number of lines from the end of the log to show. If not specified, log is shown from the creation of the container or limited by "sinceSeconds".
                • Type: int

              Was this page helpful?

              Please submit your feedback about this page through this quick form.

              Alternatively, if you don't wish to complete the quick form, you can simply indicate if you found this page helpful?

                  


              See existing feedback here.