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

Ticket creation fails when no components in JIRA project exist / JIRA rejects empty component list

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Trivial Trivial
    • jira-plugin

      Having an issue getting the plugin to create a JIRA ticket. See the configuration screenshots attached for how I've got it setup.

      The error I'm getting is during a failed build is:

      Recording test results
      ERROR: Build step failed with exception
      java.lang.NullPointerException
              at hudson.plugins.jira.JiraSession.createIssue(JiraSession.java:310)
              at hudson.plugins.jira.JiraCreateIssueNotifier.createJiraIssue(JiraCreateIssueNotifier.java:153)
              at hudson.plugins.jira.JiraCreateIssueNotifier.currentBuildResultFailure(JiraCreateIssueNotifier.java:343)
              at hudson.plugins.jira.JiraCreateIssueNotifier.perform(JiraCreateIssueNotifier.java:115)
              at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45)
              at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
              at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:726)
              at hudson.model.Build$BuildExecution.post2(Build.java:185)
              at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:671)
              at hudson.model.Run.execute(Run.java:1766)
              at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
              at hudson.model.ResourceController.execute(ResourceController.java:98)
              at hudson.model.Executor.run(Executor.java:408)
      Build step 'Create Jira Issue' marked build as failure
      

      If I call our JIRA rest API from the server I can create an issue just fine.

      curl -D- -u username:password -X POST --data @data.txt -H "Content-Type: application/json" https://destinationnsw.atlassian.net/rest/api/2/issue/
      

      data.txt contains:

      {
          "fields": {
             "project":
             {
                "key": "BUGS"
             },
             "summary": "REST ye merry gentlemen.",
             "description": "Creating of an issue using project keys",
             "issuetype": {
                "name": "Bug"
             }
         }
      }
      

      I get "HTTP/1.1 201 Created" and the ticket is available.

        1. build_changelog.png
          build_changelog.png
          35 kB
        2. build_error_message_v141.png
          build_error_message_v141.png
          46 kB
        3. build_error_message_v2.png
          build_error_message_v2.png
          66 kB
        4. create_jira_issue.png
          create_jira_issue.png
          27 kB
        5. global config.png
          global config.png
          52 kB
        6. jira_configuration.png
          jira_configuration.png
          53 kB
        7. project config.png
          project config.png
          91 kB
        8. project config - version 2.png
          project config - version 2.png
          21 kB

          [JENKINS-30682] Ticket creation fails when no components in JIRA project exist / JIRA rejects empty component list

          Sandro, your stacktrace looks different. Looks like you have an NPL on the line:

                      String comment = String.format("- Job is still failing.\n- Failed run : [%s|%s]\n** [console log|%s]",
                              buildNumber, buildURL, buildURL.concat("console"));
          

          while Thom has an NPE when actually trying to create the issue in JIRA in JiraSession class.
          That's interesting, looks like in your case buildNumber or buildURL is null.

          Radek Antoniuk added a comment - Sandro, your stacktrace looks different. Looks like you have an NPL on the line: String comment = String .format( "- Job is still failing.\n- Failed run : [%s|%s]\n** [console log|%s]" , buildNumber, buildURL, buildURL.concat( "console" )); while Thom has an NPE when actually trying to create the issue in JIRA in JiraSession class. That's interesting, looks like in your case buildNumber or buildURL is null.

          Is there anything I can try at my end? Or anything to help debugging it?

          Sandro Cirulli added a comment - Is there anything I can try at my end? Or anything to help debugging it?

          Radek Antoniuk added a comment - - edited

          thomwilhelm, what do you see in the Jenkins log? You should some error like this:

          WARNING: jira rest client create issue error. cause: RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={issuetype=valid issue type is required}, errorMessages=[]}]}
          

          Radek Antoniuk added a comment - - edited thomwilhelm , what do you see in the Jenkins log? You should some error like this: WARNING: jira rest client create issue error. cause: RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={issuetype=valid issue type is required}, errorMessages=[]}]}

          cirulls take a look at JENKINS-16225 as a wild guess. Try adding a task that runs "env" and see if variables contain BUILD_NUMBER or BUILD_URL. If they do not, you have a problem there.

          Radek Antoniuk added a comment - cirulls take a look at JENKINS-16225 as a wild guess. Try adding a task that runs "env" and see if variables contain BUILD_NUMBER or BUILD_URL. If they do not, you have a problem there.

          Thom Wilhelm added a comment -

          Hi warden in my file /var/log/jenkins/jenkins.log I'm getting the following line only when a build fails:

          INFO: Sydney.com-IN #7 main build action completed: FAILURE

          I can see some older ones from before that mention component was not found eg.

          WARNING: jira rest client create issue error. cause: RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors=

          {components=Field 'components' cannot be set. It is not on the appropriate screen, or unknown.}

          , errorMessages=[]}]}

          But I'm not entering a component value anymore. Same response as before with the NPE:

          java.lang.NullPointerException
          at hudson.plugins.jira.JiraSession.createIssue(JiraSession.java:305)
          ... etc ...

          Thom Wilhelm added a comment - Hi warden in my file /var/log/jenkins/jenkins.log I'm getting the following line only when a build fails: INFO: Sydney.com-IN #7 main build action completed: FAILURE I can see some older ones from before that mention component was not found eg. WARNING: jira rest client create issue error. cause: RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors= {components=Field 'components' cannot be set. It is not on the appropriate screen, or unknown.} , errorMessages=[]}]} But I'm not entering a component value anymore. Same response as before with the NPE: java.lang.NullPointerException at hudson.plugins.jira.JiraSession.createIssue(JiraSession.java:305) ... etc ...

          Code changed in jenkins
          User: Radosław Antoniuk
          Path:
          src/main/java/hudson/plugins/jira/JiraCreateIssueNotifier.java
          src/main/java/hudson/plugins/jira/JiraRestService.java
          src/main/java/hudson/plugins/jira/JiraSession.java
          http://jenkins-ci.org/commit/jira-plugin/43f5439fa5e5ea2dbc4b74773945b242db551913
          Log:
          JENKINS-30682 - Fix NPE on empty Component list in JIRA project. #nomerge - this was already changed in master.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Radosław Antoniuk Path: src/main/java/hudson/plugins/jira/JiraCreateIssueNotifier.java src/main/java/hudson/plugins/jira/JiraRestService.java src/main/java/hudson/plugins/jira/JiraSession.java http://jenkins-ci.org/commit/jira-plugin/43f5439fa5e5ea2dbc4b74773945b242db551913 Log: JENKINS-30682 - Fix NPE on empty Component list in JIRA project. #nomerge - this was already changed in master.

          Code changed in jenkins
          User: Radosław Antoniuk
          Path:
          src/main/java/hudson/plugins/jira/JiraCreateIssueNotifier.java
          src/main/java/hudson/plugins/jira/JiraRestService.java
          src/main/java/hudson/plugins/jira/JiraSession.java
          http://jenkins-ci.org/commit/jira-plugin/c3c8ca670a38913a2a9398a85662a0bbb8301638
          Log:
          Merge pull request #65 from jenkinsci/jira-2.0.3

          JENKINS-30682 - Fix NPE on empty Component list in JIRA project.

          Compare: https://github.com/jenkinsci/jira-plugin/compare/1a177053e8a8...c3c8ca670a38

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Radosław Antoniuk Path: src/main/java/hudson/plugins/jira/JiraCreateIssueNotifier.java src/main/java/hudson/plugins/jira/JiraRestService.java src/main/java/hudson/plugins/jira/JiraSession.java http://jenkins-ci.org/commit/jira-plugin/c3c8ca670a38913a2a9398a85662a0bbb8301638 Log: Merge pull request #65 from jenkinsci/jira-2.0.3 JENKINS-30682 - Fix NPE on empty Component list in JIRA project. Compare: https://github.com/jenkinsci/jira-plugin/compare/1a177053e8a8...c3c8ca670a38

          Code changed in jenkins
          User: Radosław Antoniuk
          Path:
          src/main/java/hudson/plugins/jira/JiraCreateIssueNotifier.java
          src/main/java/hudson/plugins/jira/JiraRestService.java
          src/main/java/hudson/plugins/jira/JiraSession.java
          http://jenkins-ci.org/commit/jira-plugin/23ee171d68e52c2f6634f11405c9620411a5c543
          Log:
          JENKINS-30682 - Fix NPE on empty Component list in JIRA project. #nomerge - this was already changed in master.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Radosław Antoniuk Path: src/main/java/hudson/plugins/jira/JiraCreateIssueNotifier.java src/main/java/hudson/plugins/jira/JiraRestService.java src/main/java/hudson/plugins/jira/JiraSession.java http://jenkins-ci.org/commit/jira-plugin/23ee171d68e52c2f6634f11405c9620411a5c543 Log: JENKINS-30682 - Fix NPE on empty Component list in JIRA project. #nomerge - this was already changed in master.

          Thom, I just released v.2.0.3, give it a try and let me know how it goes.

          Radek Antoniuk added a comment - Thom, I just released v.2.0.3, give it a try and let me know how it goes.

          Thom Wilhelm added a comment -

          Hey warden thanks so much that's fixed the issue for us. Legend.

          Big up yourself.

          Thom Wilhelm added a comment - Hey warden thanks so much that's fixed the issue for us. Legend. Big up yourself.

            warden Radek Antoniuk
            thomwilhelm Thom Wilhelm
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: