<p>I am using the Jenkins <a href="https://wiki.jenkins.io/display/JENKINS/Kubernetes+Plugin" rel="nofollow noreferrer">kubernetes plugin</a> to run pipeline builds:</p>

<pre><code>pipeline {
  agent {
    kubernetes {
      label 'kind'
      defaultContainer 'jnlp'
      yaml """
apiVersion: v1
kind: Pod
metadata:
  labels:
    name: dind
... 
</code></pre>

<p>I want to template a particular field of the yaml with an integer between 0 and 5 that is rotated in a round robin fashion (i.e. first build is templated with 0, second build templated with 1 etc. and goes back to 0 again after 4).</p>

<p>How can I achieve this?</p>

dippynark
<p>You can use podTemplates next code is from <a href="https://github.com/jenkinsci/kubernetes-plugin" rel="nofollow noreferrer">https://github.com/jenkinsci/kubernetes-plugin</a>, you can use variables to prepare any kind of pods you need.
If this is not what you need, can you provide an example of what you are trying to do?</p>

<pre><code>def label = "mypod-${UUID.randomUUID().toString()}"
podTemplate(label: label, containers: [
  containerTemplate(name: 'maven', image: 'maven:3.3.9-jdk-8-alpine', ttyEnabled: true, command: 'cat'),
  containerTemplate(name: 'golang', image: 'golang:1.8.0', ttyEnabled: true, command: 'cat')
]) {

node(label) {
    stage('Get a Maven project') {
        git 'https://github.com/jenkinsci/kubernetes-plugin.git'
        container('maven') {
            stage('Build a Maven project') {
                sh 'mvn -B clean install'
            }
        }
    }

    stage('Get a Golang project') {
        git url: 'https://github.com/hashicorp/terraform.git'
        container('golang') {
            stage('Build a Go project') {
                sh """
                mkdir -p /go/src/github.com/hashicorp
                ln -s `pwd` /go/src/github.com/hashicorp/terraform
                cd /go/src/github.com/hashicorp/terraform &amp;&amp; make core-dev
                """
            }
        }
    }

}
</code></pre>

<p>}</p>
