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

Github Issues plugin not working in pipeline

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Component/s: github-issues-plugin
    • Labels:
      None
    • Environment:
      Jenkins 2.48; Github Issues plugin 1.2.2
    • Similar Issues:

      Description

      Attempting to use this plugin within a pipeline, I get the following exception:

      java.lang.ClassCastException: org.jenkinsci.plugins.workflow.job.WorkflowRun cannot be cast to hudson.model.AbstractBuild
      	at org.jenkinsci.plugins.githubissues.GitHubIssueNotifier.perform(GitHubIssueNotifier.java:139)
      	at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:78)
      	at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:65)
      	at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1$1.call(SynchronousNonBlockingStepExecution.java:49)
      	at hudson.security.ACL.impersonate(ACL.java:260)
      	at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1.run(SynchronousNonBlockingStepExecution.java:46)
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:473)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      	at java.lang.Thread.run(Thread.java:745)
      

      The pipeline script is:

      node {
          try {
              sh "ls 1234"
          }
          finally {
              step([$class: 'GitHubIssueNotifier', 
                  issueAppend: true, issueBody: '''
                  Build \'$JOB_NAME\' has failed!
                  
                  Last 50 lines of output:
                  
                  ```
                  ${OUTPUT, lines=50}
                  ```
                  
                  [View full output]($BUILD_URL)''', 
                  issueLabel: 'Urgency-High', 
                  issueRepo: '<a repo>', 
                  issueTitle: '$JOB_NAME $BUILD_DISPLAY_NAME failed'])
          }
      }
      

        Attachments

          Activity

          Hide
          daniel15 Daniel Lo Nigro added a comment -

          Thanks for the bug report. I'm not very familiar with pipeline  so I'll try to investigate and determine how to fix this. The code for the plugin is on GitHub so feel free to take a look if you're familiar with how pipelines work

          Show
          daniel15 Daniel Lo Nigro added a comment - Thanks for the bug report. I'm not very familiar with pipeline  so I'll try to investigate and determine how to fix this. The code for the plugin is on GitHub so feel free to take a look if you're familiar with how pipelines work
          Hide
          benjamin_gill Benjamin Gill added a comment -

          I'm not a Java expert. However, it looks as if the problem is at https://github.com/jenkinsci/github-issues-plugin/blob/master/src/main/java/org/jenkinsci/plugins/githubissues/GitHubIssueNotifier.java#L139, where we convert to an `AbstractBuild` to pass into the `getLastestIssueAction` funtion (https://github.com/jenkinsci/github-issues-plugin/blob/master/src/main/java/org/jenkinsci/plugins/githubissues/GitHubIssueNotifier.java#L192).

           

          When we're running in a pipeline, we seem to get a http://javadoc.jenkins.io/plugin/workflow-job/org/jenkinsci/plugins/workflow/job/WorkflowRun.html rather than an http://javadoc.jenkins-ci.org/hudson/model/AbstractBuild.html. Both, however, expose similar methods - `getAction` and `getPreviousBuild`.

           

          I don't know how one would do this, but would it be possible to detect which of the two classes you have, and cast accordingly?

          Show
          benjamin_gill Benjamin Gill added a comment - I'm not a Java expert. However, it looks as if the problem is at https://github.com/jenkinsci/github-issues-plugin/blob/master/src/main/java/org/jenkinsci/plugins/githubissues/GitHubIssueNotifier.java#L139,  where we convert to an `AbstractBuild` to pass into the `getLastestIssueAction` funtion ( https://github.com/jenkinsci/github-issues-plugin/blob/master/src/main/java/org/jenkinsci/plugins/githubissues/GitHubIssueNotifier.java#L192).   When we're running in a pipeline, we seem to get a http://javadoc.jenkins.io/plugin/workflow-job/org/jenkinsci/plugins/workflow/job/WorkflowRun.html  rather than an http://javadoc.jenkins-ci.org/hudson/model/AbstractBuild.html.  Both, however, expose similar methods - `getAction` and `getPreviousBuild`.   I don't know how one would do this, but would it be possible to detect which of the two classes you have, and cast accordingly?
          Hide
          benjamin_gill Benjamin Gill added a comment -

          I've just submitted https://github.com/jenkinsci/github-issues-plugin/pull/8

          It should work, but I haven't been able to test it against a workflow.

          Show
          benjamin_gill Benjamin Gill added a comment - I've just submitted https://github.com/jenkinsci/github-issues-plugin/pull/8 It should work, but I haven't been able to test it against a workflow.
          Hide
          benjamin_gill Benjamin Gill added a comment -

          I've been using it for the past 3 weeks now without incident.

          Show
          benjamin_gill Benjamin Gill added a comment - I've been using it for the past 3 weeks now without incident.
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Benjamin Gill
          Path:
          src/main/java/org/jenkinsci/plugins/githubissues/GitHubIssueNotifier.java
          http://jenkins-ci.org/commit/github-issues-plugin/31dca10e324e6fbd0c7cab0b422b387263f32329
          Log:
          Add workflow support (#8)

          • Add workflow support

          Should resolve JENKINS-42629

          • Run covers everything
          • Treat null Result as success

          In pipelines, Result is only set at the end. The common pattern is to
          explicitly set it to failed/unstable. Thus, we can assume that null =>
          success.

          • Explain `result == null`
          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Benjamin Gill Path: src/main/java/org/jenkinsci/plugins/githubissues/GitHubIssueNotifier.java http://jenkins-ci.org/commit/github-issues-plugin/31dca10e324e6fbd0c7cab0b422b387263f32329 Log: Add workflow support (#8) Add workflow support Should resolve JENKINS-42629 Run covers everything Treat null Result as success In pipelines, Result is only set at the end. The common pattern is to explicitly set it to failed/unstable. Thus, we can assume that null => success. Explain `result == null`
          Hide
          benjamin_gill Benjamin Gill added a comment -

          Thank you. If you let me know when you release the next version, I'll update the documentation on the wiki as per https://github.com/jenkinsci/github-issues-plugin/pull/8#issuecomment-309057719 

          Show
          benjamin_gill Benjamin Gill added a comment - Thank you. If you let me know when you release the next version, I'll update the documentation on the wiki as per https://github.com/jenkinsci/github-issues-plugin/pull/8#issuecomment-309057719  
          Hide
          daniel15 Daniel Lo Nigro added a comment -

          Sure. I'll most likely release the updated version this weekend.

          Show
          daniel15 Daniel Lo Nigro added a comment - Sure. I'll most likely release the updated version this weekend.
          Hide
          daniel15 Daniel Lo Nigro added a comment -

          Published as v1.2.3. Thanks for your contribution!

          Show
          daniel15 Daniel Lo Nigro added a comment - Published as v1.2.3. Thanks for your contribution!

            People

            • Assignee:
              daniel15 Daniel Lo Nigro
              Reporter:
              benjamin_gill Benjamin Gill
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: