Interview Prep/Jenkins/Plugins, JCasC & Jenkins on Kubernetes

How do you define a pod template inline in a declarative pipeline?

IntermediateConceptPlugins, JCasC & Jenkins on Kubernetes
Answer
agent {
  kubernetes {
    defaultContainer 'maven'
    yaml '''
apiVersion: v1
kind: Pod
spec:
  containers:
    - name: maven
      image: maven:3.9-eclipse-temurin-21
      command: ["sleep"]
      args: ["infinity"]
      resources:
        requests: { cpu: "1", memory: "2Gi" }
        limits: { memory: "2Gi" }
'''
  }
}

Tool containers must stay alive (sleep infinity or cat with tty: true); the plugin adds the jnlp container automatically. yamlFile 'ci/pod.yaml' reads the template from the repo instead.

All Jenkins questions Roadmap: Jenkins

More on Plugins, JCasC & Jenkins on Kubernetes