Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-57830

Better default for PodTemplateStep.label

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Major Major
    • kubernetes-plugin
    • 1.17.0

      Various examples in documentation and tests either set a hard-coded label for the podTemplate step, which is a race condition waiting to happen, or use ugly Groovy scripting with UUID.randomUUID(). These would better be simplified to use the standard Jenkins environment variable BUILD_TAG, which is unique per build and is also meaningful to humans trying to debug label assignments and node provisioning:

      podTemplate(label: BUILD_TAG, containers: [containerTemplate(name: 'ubuntu', image: 'ubuntu', command: 'sleep', args: 'infinity')]) {
          node (BUILD_TAG) {
              container('ubuntu') {
                  sh 'whoami'
              }
          }
      }
      

      For Declarative, there is no good reason to force the user to define the label at all (see Declarative tests using label: '...'); KubernetesDeclarativeAgent.label could simply be defaulted to something such as BUILD_TAG.

            jglick Jesse Glick
            jglick Jesse Glick
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: