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

Support plugin run in downstream jobs

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Fixed
    • Icon: Critical Critical
    • sonar-gerrit-plugin
    • None
    • Any environment

      In case if the plugin is run out of a job with Gerrit Trigger, plugin fails with NPE:

      java.lang.NullPointerException
       at org.jenkinsci.plugins.sonargerrit.SonarToGerritBuilder.perform(SonarToGerritBuilder.java:149)
      

      It happens because the plugin tries to get current Gerrit server name from GerritTrigger instance in current job and can't find it.

      Overall, the plugin must support run in jobs which have no GerritTrigger instance, for example in subjobs of multijob, or workflow jobs.

      There's a three parameters plugin needs to post changes to Gerrt:

      • Server name - used to get REST API information from GerritManagement.
      • Change number - Used to retrieve necessary change from Gerrit server.
      • Patchset number - Used to retrieve necessary patchset from Gerrit server.

      In current GerritTrigger implementation all parameters are put in environment parameters by Gerrit triiger on tirggering:

      • Server name - GERRIT_NAME
      • Change number - GERRIT_CHANGE_NUMBER
      • Patchset number - GERRIT_PATCHSET_NUMBER

      So to support the plugin work in any job those parameters must be available as enviroment variables, what is pretty easy to do and pass from main job with GerritTrigger.

      To support such run plugin must follow the next logic:

      When GERRIT_NAME is available in current build EnvVars,
      Then use is as server name.

      When GERRIT_NAME is not available in current build EnvVars,
      Then use GerritTrigger.getTrigger(build.getProject()) to get trigger instance for current job and get server name from the instance.

      When GERRIT_NAME is not available in current build EnvVars and there's no gerrit trigger instance for this job,
      Then log error and fail build step.

      Additional section of wiki is required to describe steps to run plugin in job without GerritTrigger plugin inside.

            aquarellian Tatiana Didik
            adidik Aleksey Didik
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: