<p>I was using <a href="https://github.com/jenkinsci/kubernetes-plugin" rel="noreferrer">kuberntes-plugin</a>. In its README it has given how to write scripted pipeline with multiple container images, like </p>

<pre><code>podTemplate(label: 'mypod', 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('mypod') { 
</code></pre>

<p>I tried the following for declarative pipeline.</p>

<pre><code>pipeline {
  agent {
    kubernetes {
      //cloud 'kubernetes'
      label 'mypod'
      containerTemplate {
        name 'maven'
        image 'maven:3.3.9-jdk-8-alpine'
        ttyEnabled true
        command 'cat'
      }
      containerTemplate {
        name 'containtertwo'
        image 'someimage'
        ttyEnabled true

      }
    }
  }
</code></pre>

<p>It creates a pod with only one container. </p>

<p>how to use multiple containerTemplates with declarative pipeline?</p>

<p>This isnt a solution to your problem, but is some information I found after looking.</p>

<p>The <a href="https://github.com/jenkinsci/kubernetes-plugin/blob/master/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesDeclarativeAgent.java#L28" rel="nofollow noreferrer">KubernetesDeclarativeAgent</a> only has a single <code>containerTemplate</code>. Whichever <code>containerTemplate</code> is at the bottom of your collection of containers will be the one that is used.</p>

<p>In your example it will be <code>containtertwo</code>.</p>

<p>You cant have multiple top level <code>agents</code>, and you cant have multiple <code>kubernetes</code> within an agent. And now you cant have multiple containers. I would prefer if an error or warning of some kind was thrown for this.</p>

<p>There are 2 work arounds I can think of. If you must use declarative, then you can add an <code>agent</code> to your <code>stage</code>, but this can lead to its own issues. The other is the scripted pipeline, which is what I am going to do.</p>

<p>The documentation on this leaves much to be desired.</p>
