Running jenkins pipelines on kubernetes

I have an example of running jenkins pipelines on kubernetes where every step is executed in separate container.

Jenkins pod running with 3 containers (kubectl get pod -w)

By default the first container (first of 3/3) is the jenkins slave and the rest can be defined in the pipeline. In my example the other two containers are ‘tf’ running terraform (default if step doesn’t define which container to run within) and ‘ansible’ with just ansible.

agent {    
kubernetes {
defaultContainer 'tf'
yamlFile 'pipelines/additionalAgents.yaml'

Pod manifest lives inside yaml file, declaring where to pull images from and what secret to use in the case of private registry

Manifest with Jenkins containers

The steps in the example include ‘sleep’ command for demonstration purpose.

Steps to run in each container