<p>I am trying to create a pipeline job for <code>Angular</code> code to deploy the application into k8 cluster. Below there is a code for pipeline container <code>podTemplate</code>, during the build I get the next error.</p>

<pre><code>def label = "worker-${UUID.randomUUID().toString()}"

podTemplate(
    cloud: 'kubernetes',
    namespace: 'test',
    imagePullSecrets: ['regcred'],
    label: label,
    containers: [
        containerTemplate(name: 'nodejs', image: 'nodejscn/node:latest', ttyEnabled: true, command: 'cat'),
        containerTemplate(name: 'docker', image: 'nodejscn/node:latest', ttyEnabled: true, command: 'cat'),
        containerTemplate(name: 'kubectl', image: 'k8spoc1/kubctl:latest', ttyEnabled: true, command: 'cat')
    ],
    volumes: [
        hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock'),
        hostPathVolume(hostPath: '/root/.m2/repository', mountPath: '/root/.m2/repository')
    ]
) {

    node(label) {
      def scmInfo = checkout scm
      def image_tag
      def image_name
      sh 'pwd'
      def gitCommit = scmInfo.GIT_COMMIT
      def gitBranch = scmInfo.GIT_BRANCH
      def commitId
      commitId= scmInfo.GIT_COMMIT[0..7]
      image_tag = "${scmInfo.GIT_BRANCH}-${scmInfo.GIT_COMMIT[0..7]}"

      stage('NPM Install') {
           container ('nodejs') {
              withEnv(["NPM_CONFIG_LOGLEVEL=warn"]) {
                sh 'npm install'
            }
           }
      }
   }
}

</code></pre>

<p>Error from Jenkins:</p>

<pre><code>[Pipeline] Start of Pipeline
[Pipeline] podTemplate
[Pipeline] // podTemplate
[Pipeline] End of Pipeline
ERROR: Labels must follow required specs - https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set:  Ubuntu-82f3782f-b5aa-4029-9c51-57610153747c
Finished: FAILURE
</code></pre>

<p>Do I need to mention a <code>spec</code> value of my <code>Jenkins</code> file?</p>

<p>The error message you get:</p>

<pre><code>ERROR: Labels must follow required specs - https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set:  Ubuntu-82f3782f-b5aa-4029-9c51-57610153747c
</code></pre>

<p>points out quite precisely what can be wrong with your <code>Pod</code> template. As you can see in <a href="https://kubernetes.io/docs/concepts/overv" rel="nofollow noreferrer">link</a> to kubernetes documentation given in the <code>ERROR</code> message, you need to follow certain rules when defining a <code>Pod</code>. <code>labels</code> element is a <code>dictionary</code>/<code>map</code> field that requires you to provide at least one key-value pair so you cannot just write <code>label: label</code> in your specification.</p>

<p>You can try to define your <code>PodTemplate</code> in <code>yaml</code> format (which is mostly used in <strong>kubernetes</strong>) like in <a href="https://github.com/jenkinsci/kubernetes-plugin#using-yaml-to-define-pod-templates" rel="nofollow noreferrer">this</a> example:</p>

<pre><code>podTemplate(yaml: """
apiVersion: v1
kind: Pod
metadata:
  labels:
    some-label: some-label-value
spec:
  containers:
  - name: busybox
    image: busybox
    command:
    - cat
    tty: true
"""
) {
    node(POD_LABEL) {
      container('busybox') {
        sh "hostname"
      }
    }
}
</code></pre>

<p>As you can read <a href="https://github.com/jenkinsci/kubernetes-plugin#pod-and-container-template-configuration" rel="nofollow noreferrer">here</a>:</p>

<blockquote>
  <p>label The label of the pod. Can be set to a unique value to avoid
  conflicts across builds, or omitted and POD_LABEL will be defined
  inside the step.</p>
</blockquote>

<p><code>label</code> field can be omitted at all so first you can try without it and you shouldn't get any error message.</p>
