jenkinsci / pipeline-github-plugin

Pipeline: GitHub
https://plugins.jenkins.io/pipeline-github/
MIT License
159 stars 73 forks source link

`pullRequest.deleteBranch()` method failing with error: `java.lang.IllegalArgumentException: Job's SCM is not GitHub` #114

Closed aRobinson-R7 closed 2 years ago

aRobinson-R7 commented 2 years ago

Jenkins and plugins versions report

Environment ```text Jenkins: 2.346.2 OS: Linux - 5.4.188-104.359.amzn2.x86_64 --- pipeline-github:2.8-138.d766e30bb08b ```

What Operating System are you using (both controller, and any agents involved in the problem)?

Kubernetes, version listed above

Reproduction steps

  1. Work with PR in previous stages
  2. Merge PR with this plugin pullRequest.merge("")
  3. Create a commit on the main branch with CHANGELOG and README updates
  4. Delete branch using pullRequest.deleteBranch()
  5. This error then occurs occasionally

Expected Results

Branch is deleted by job, job completes successfully

Actual Results

Branch is not deleted, job fails with the following stacktrace:

java.lang.IllegalArgumentException: Job's SCM is not GitHub.
    at org.jenkinsci.plugins.pipeline.github.GitHubHelper.getGitHubClient(GitHubHelper.java:78)
    at org.jenkinsci.plugins.pipeline.github.PullRequestGroovyObject.getGitHubClient(PullRequestGroovyObject.java:97)
    at org.jenkinsci.plugins.pipeline.github.PullRequestGroovyObject.getPullRequestService(PullRequestGroovyObject.java:104)
    at org.jenkinsci.plugins.pipeline.github.PullRequestGroovyObject.<init>(PullRequestGroovyObject.java:82)
    at org.jenkinsci.plugins.pipeline.github.PullRequestGlobalVariable.getValue(PullRequestGlobalVariable.java:30)
    at org.jenkinsci.plugins.workflow.cps.CpsScript.getProperty(CpsScript.java:137)
    at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:190)
    at groovy.lang.Closure.getPropertyTryThese(Closure.java:318)
    at groovy.lang.Closure.getPropertyDelegateFirst(Closure.java:308)
    at groovy.lang.Closure.getProperty(Closure.java:293)
    at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:190)
    at groovy.lang.Closure.getPropertyTryThese(Closure.java:318)
    at groovy.lang.Closure.getPropertyOwnerFirst(Closure.java:312)
    at groovy.lang.Closure.getProperty(Closure.java:301)
    at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:190)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:469)
    at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.getProperty(DefaultInvoker.java:39)
    at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
    at terraformReleasePipeline.call(terraformReleasePipeline.groovy:305)
    at ___cps.transform___(Native Method)
    at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:74)
    at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
    at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.fixName(PropertyishBlock.java:66)
    at jdk.internal.reflect.GeneratedMethodAccessor426.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
    at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
    at com.cloudbees.groovy.cps.Next.step(Next.java:83)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
    at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:136)
    at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:275)
    at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
    at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:187)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:420)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:95)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:330)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:294)
    at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:139)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
    at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)
Finished: FAILURE

Anything else?

This does not happen for every job / PR, but it has happened a few times recently. As we are closing the PR using pullRequest.merge("") as well as using other functionality to grab information about the PR, we know this is a valid command.

This does work on previous and subsequent new PRs on the repository, it only seems to fail intermittently. As it's only deleting the branch at the end of the release it is not a breaking issue, but it is causing confusion for end-users. Could it be related that we directly use git before this command to switch branch and do a commit onto the release branch? But then why would it only occasionly fail?

aRobinson-R7 commented 2 years ago

This may be due to the time between the merge and the delete - moving them beside one another in the Jenkinsfile seems to have resolved the issue