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

job-dsl allocatePorts does not work

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Minor Minor
    • None
    • Jenkins 1.596.3 LTS, job-dsl-plugin 1.34, port-allocator-plugin 1.8

      I fail to create a job with an unique TCP port allocated via job-dsl. The following DSL

      freeStyleJob('Test Port Allocation') {
        wrappers {
          allocatePorts 'WEBAPP_HOST_PORT'
        }
      
        steps {
          shell 'env'
        }
      }
      

      generates a Job but the TCP port is missing in the web gui configuration page. When running the generated job no port is allocated.

      The generated config.xml, however, does contain a buildWrappers section about the port:

      <buildWrappers>
      <org.jvnet.hudson.plugins.port__allocator.PortAllocator>
      <ports>
      <org.jvnet.hudson.plugins.port__allocator.DefaultPortType>
      <name>WEBAPP_HOST_PORT</name>
      </org.jvnet.hudson.plugins.port__allocator.DefaultPortType>
      </ports>
      </org.jvnet.hudson.plugins.port__allocator.PortAllocator>
      </buildWrappers>

      Manually configuring the tcp port does work and generates the following buildWrappers block in config.xml

      <buildWrappers>
      <org.jvnet.hudson.plugins.port__allocator.PortAllocator
      plugin="port-allocator@1.8">
      <ports>
      <org.jvnet.hudson.plugins.port__allocator.DefaultPortType>
      <name>WEBAPP_HOST_PORT</name>
      </org.jvnet.hudson.plugins.port__allocator.DefaultPortType>
      </ports>
      </org.jvnet.hudson.plugins.port__allocator.PortAllocator>
      </buildWrappers>

      The only difference I can find, is the plugin attribute of the PortAllocator tag. A tried to match the resulting config.xml with the following DSL but this did not help even though the resulting {{config.xml}}s had identical buildWrappers blocks.

      freeStyleJob('Test Port Allocation') {
        wrappers {
          allocatePorts 'WEBAPP_HOST_PORT'
        }
      
        steps {
          shell 'env'
        }
      
        configure { projectNode ->
          portAllocatorNode = projectNode / buildWrappers / 'org.jvnet.hudson.plugins.port__allocator.PortAllocator'
          portAllocatorNode.@plugin = 'port-allocator@1.8'
        }
      }
      

            daspilker Daniel Spilker
            holznera Andreas Holzner
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: