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

Support plugin run in downstream jobs

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Resolved (View Workflow)
    • Priority: Critical
    • Resolution: Fixed
    • Component/s: sonar-gerrit-plugin
    • Labels:
      None
    • Environment:
      Any environment
    • Similar Issues:

      Description

      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.

        Attachments

          Activity

          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Tatiana Didik
          Path:
          src/main/java/org/jenkinsci/plugins/sonargerrit/SonarToGerritBuilder.java
          src/main/resources/messages.properties
          http://jenkins-ci.org/commit/sonar-gerrit-plugin/5313885bc6c11cd5fb237e79bd1fd6b6299c9232
          Log:
          JENKINS-30915 Support plugin run in dounstream jobs

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Tatiana Didik Path: src/main/java/org/jenkinsci/plugins/sonargerrit/SonarToGerritBuilder.java src/main/resources/messages.properties http://jenkins-ci.org/commit/sonar-gerrit-plugin/5313885bc6c11cd5fb237e79bd1fd6b6299c9232 Log: JENKINS-30915 Support plugin run in dounstream jobs

            People

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

              Dates

              • Created:
                Updated:
                Resolved: