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

Excessive querying of change information




      While debugging JENKINS-60833 I also noticed an extreme number of identical requests was made to the Gerrit server for each build. It turns out that for each sh step Gerrit Code Review Plugin makes four requests to the same url:


      So, in a Jenkinsfile with a handfull sh steps this quickly becomes quite a lot of requests. E.g. the following will make 81 identical requests to the Gerrit server:

      node {
          for (int i = 0; i < 20; i++) {
              sh "echo Loop ${i}"

      The root cause of this is that GerritEnvironmentContributor is called repeatedly each time the Pipeline execution needs to execute long duration steps (or something like that). Worth noting in the documentation for EnvironmentContributor#buildEnvironmentFor(Job, ...):

      This method can be called repeatedly for the same {@link Job}, thus the computation of this method needs to be efficient.

      ... which (in my opinion) doesn't play well with the repeated HTTP requests to the Gerrit server.

      One possible fix is to instead implement EnvironmentContributor#buildEnvironmentFor(Run, ...) and then compute once and store as InvisibleAction (as per JavaDoc comments for the method). Now, the question is whether there is a special reason that the Job version is implemented instead of Run version? lucamilanesio, maybe you have som insights to why this is? If not it should be a fairly easy fix.




            lucamilanesio Luca Domenico Milanesio
            jons Jon Sten
            0 Vote for this issue
            2 Start watching this issue