<p>I am using the OpenShift Jenkins image within an OpenShift Cluster. This default Jenkins image results in a Jenkins container that is preconfigured to point to my Kubernetes cluster. Additionally, the container has two Kubernetes pod templates defined, one for maven and one for nodejs.</p>

<p><a href="https://i.stack.imgur.com/GzPQz.png" rel="noreferrer"><img src="https://i.stack.imgur.com/GzPQz.png" alt="enter image description here"></a></p>

<p><a href="https://i.stack.imgur.com/uwPWl.png" rel="noreferrer"><img src="https://i.stack.imgur.com/uwPWl.png" alt="enter image description here"></a></p>

<p>What I would now like to do is use a declarative pipeline and reference these pods. I tried the following</p>

<pre><code>  agent {
     kubernetes {
     //cloud 'kubernetes'
     label 'maven'
     }
  }
</code></pre>

<p>But that gives an error stating</p>

<blockquote>
  <p>org.codehaus.groovy.control.MultipleCompilationErrorsException:
  startup failed:</p>
  
  <p>WorkflowScript: 4: Missing required parameter for agent type
  "kubernetes": containerTemplate @ line 4, column 10.</p>

<pre><code>        kubernetes {

        ^
</code></pre>
</blockquote>

<p>All of the (<a href="https://github.com/jenkinsci/kubernetes-plugin/blob/master/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/declarative.groovy" rel="noreferrer">examples</a>) that I can find for declarative pipelines show the pod templates being defined when the agent is specified.</p>

<p>Is it possible to reuse already defined templates in a declarative pipeline?</p>

<p>Here is an example using a pre-defined pod template.</p>

<pre><code>pipeline {
  agent {
      label "maven"
  }
  stages {
    stage('Run maven') {
      steps {
        sh 'mvn -version'
      }
    }
  }
}
</code></pre>

<p>Your original pipeline definition was in effect defining a brand new pod template and hence the error enforcing the requirement for <code>containerTeamplates</code> parameter. When using an existing template, you can simply specify the label in the <code>agent</code> block.</p>
