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

Howto define a fallback label in case all hosts for default label are busy?

    Details

    • Similar Issues:

      Description

      Unfortunately the pluign documentation is a bit short and should cover more use cases. One of them is the assignment of a default label and, in case all hosts with that label are busy, a fallback label so that the job only has to wait if all hosts with both labels are busy. This would allow to specify a preference for faster hosts and fall back to slower ones if all fast hosts are busy.

      Here's what I've tried so far:

      import jenkins.model.Jenkins
      
      Jenkins.instance.getLabel('FastHost').getNodes().each { agent ->
        def executors = agent.getComputer().numExecutors
        def busy = agent.getComputer().countBusy()
        if (busy < executors) {
          return "FastHost"
        }
      }
      return "SlowHost"
      

      But this always returns "SlowHost", no matter how many executors are free on "FastHost" hosts.

        Attachments

          Activity

          Hide
          dhs Dirk Heinrichs added a comment - - edited

          Seems I shouldn't "return" while inside "each". Works with the following modification:

          import jenkins.model.Jenkins
          
          def label = 'SlowHost'
          Jenkins.instance.getLabel('FastHost').getNodes().each { agent ->
            def executors = agent.getComputer().numExecutors
            def busy = agent.getComputer().countBusy()
            if (busy < executors) {
              label = 'FastHost'
            }
          }
          return label
          Show
          dhs Dirk Heinrichs added a comment - - edited Seems I shouldn't "return" while inside "each". Works with the following modification: import jenkins.model.Jenkins def label = 'SlowHost' Jenkins.instance.getLabel( 'FastHost' ).getNodes().each { agent -> def executors = agent.getComputer().numExecutors def busy = agent.getComputer().countBusy() if (busy < executors) { label = 'FastHost' } } return label
          Hide
          ikedam ikedam added a comment -

          Looks resolved by the reporter.
          Anyway, it’s an issue of the language specification of groovy. This plugin expects users know how to write groovy codes.

          You may add example codes in the plugin page as it’s a Wiki page. Improvements are welcome.

          Show
          ikedam ikedam added a comment - Looks resolved by the reporter. Anyway, it’s an issue of the language specification of groovy. This plugin expects users know how to write groovy codes. You may add example codes in the plugin page as it’s a Wiki page. Improvements are welcome.
          Hide
          dhs Dirk Heinrichs added a comment -

          Well, the idea was to add it to the documentation as an example of how to use Jenkins internals

          Show
          dhs Dirk Heinrichs added a comment - Well, the idea was to add it to the documentation as an example of how to use Jenkins internals

            People

            • Assignee:
              dhs Dirk Heinrichs
              Reporter:
              dhs Dirk Heinrichs
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: