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

Throttled jobs get throttled when jobs running, but all throttled jobs start together once running job is finished

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • Ubuntu 18.04.5
      openjdk "1.8.0_275"
      Jenkins 2.269
      throttle-concurrent-builds 2.0.3

      Hello,

      I have a bunch of jobs that I need to throttle so that only one of them is running at any given time. On our old Jenkins instance that we're migrating away from, we had been using throttle-concurrent-builds combined with it's categories feature to achieve this. We've attempted to replicate this, however, the difference now is that we're using job-dsl to generate the jobs, and using Jenkinsfiles to have our pipelines in code.

      On our new Jenkins instance however, this doesn't seem to be fully working. We are observing the following behaviour:

      Imagine there are 3 jobs, Jobs A through C

      We have Job A that is currently running. While Job A is running, any other jobs (that is B and C), get queued as expected.  Once Job A finishes, jobs B and C get scheduled straight away so that now both jobs are running.

      This is obviously not desired behaviour, and we only need to run a single job at a time.

      I've had a look through the config.xml that gets generated on our new instance, and compared it with our old instance and below is the diff:

      diff --git 1/old.xml 2/new.xml
      index 9b0bb66..747ad8f 100644
      --- 1/old.xml
      +++ 2/new.xml
      @@ -1,15 +1,15 @@
       <?xml version="1.0"?>
       <properties>
      -  <hudson.plugins.throttleconcurrents.ThrottleJobProperty plugin="throttle-concurrents@2.0.1">
      +  <org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty/>
      +  <hudson.plugins.throttleconcurrents.ThrottleJobProperty plugin="throttle-concurrents@2.0.3">
           <maxConcurrentPerNode>1</maxConcurrentPerNode>
           <maxConcurrentTotal>1</maxConcurrentTotal>
      -    <categories class="java.util.concurrent.CopyOnWriteArrayList">
      -      <string>my-category</string>
      +    <categories>
      +      <string>my-pipeline-category</string>
           </categories>
           <throttleEnabled>true</throttleEnabled>
           <throttleOption>category</throttleOption>
           <limitOneJobWithMatchingParams>false</limitOneJobWithMatchingParams>
      -    <paramsToUseForLimit>PIPELINE_MODE</paramsToUseForLimit>
           <configVersion>1</configVersion>
         </hudson.plugins.throttleconcurrents.ThrottleJobProperty>
       </properties>

      Couple of notes, the parameter `PIPELINE_MODE` has been removed on our new instance, but from looking at the code for the plugin, it looks to me like `paramsToUseForLimit` attribute is ignored when `limitOneJobWithMatchingParams` is set to false.

      Furthermore, I'm not quite sure where `DisableConcurrentBuildsJobProperty` comes from, and I'm not really sure if this is what could be causing it.

      Our Job DSL (which is pretty much the same for all jobs):

      pipelineJob("myjob") {
          concurrentBuild(false)
      
          properties {
              throttleJobProperty {
                  throttleEnabled(true)
                  throttleOption('category')
                  categories(['my-pipeline-category'])
                  maxConcurrentPerNode(1)
                  maxConcurrentTotal(1)
                  limitOneJobWithMatchingParams(false)
                  paramsToUseForLimit(null)
                  matrixOptions {
                      throttleMatrixBuilds(true)
                      throttleMatrixConfigurations(false)
                  }
              }
          }
          
          definition {
              cpsScm {
                  scm {
                      git {
                          remote {
                              url('https://github.com/xxx/xxx.git')
                              credentials('xxxx')
                          }
                      }
                  }
      
                  scriptPath('Jenkinsfile')
              }
          }
      } 

      This looks to me like a bug, but I'm not entirely sure.

      Steps to reproduce the issue have been added as a comment.

            Unassigned Unassigned
            thehosh Hosh
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: