Issue
-
I would like to use an external pod description yaml file for my build agent, either coming from:
-
The workspace
Environment
Resolution
Getting the pod template from the workspace
Kubernetes plugin >= 1.17
-
Mention the path to the yaml file using the yamlFile parameter
pipeline { agent { kubernetes { defaultContainer 'maven' yamlFile 'KubernetesPod.yaml' } } stages { stage('Run maven') { steps { sh 'mvn -version' } } } }
Kubernetes plugin < 1.17
-
Mention the path to the yaml file using the yamlFile parameter
-
Provide the build agent name prefix using the label parameter
Not providing the label parameter will cause the system to use the default pod template, ignoring the yamlFile parameter.
pipeline { agent { kubernetes { defaultContainer 'maven' label 'build-agent-name-prefix' yamlFile 'KubernetesPod.yaml' } } stages { stage('Run maven') { steps { sh 'mvn -version' } } } }
Getting the pod template from a shared library
Kubernetes plugin >= 1.17
-
Mention the path to the yaml file using the yaml libraryResource parameter
pipeline { agent { kubernetes { defaultContainer 'maven' yaml libraryResource('podTemplates/maven.yaml') } } stages { stage('Run maven') { steps { sh 'mvn -version' } } } }
Kubernetes plugin < 1.17
-
Mention the path to the yaml file using the yaml libraryResource parameter
-
Provide the build agent name prefix using the label parameter
Not providing the label parameter will cause the system to use the default pod template, ignoring the yaml libraryResource parameter.
pipeline { agent { kubernetes { defaultContainer 'maven' label 'build-agent-name-prefix' yaml libraryResource('podTemplates/maven.yaml') } } stages { stage('Run maven') { steps { sh 'mvn -version' } } } }