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.
More on Plugins, JCasC & Jenkins on Kubernetes
How do you manage plugins in a reproducible way?IntermediateWhat does `jenkins-plugin-cli` resolve for you, and what flags matter?IntermediateWhy should you keep the number of plugins low?BeginnerWhat is JCasC and how is it loaded?BeginnerWhat are the top-level root elements in a JCasC file?IntermediateHow do you inject secrets into JCasC without committing them?Advanced