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

Jenkins use wrong commit SHA when pulling shared library

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • OS Ubuntu 18.04.2 LTS
      Jenkins ver. 2.164.1
      Bitbucket Pullrequest Builder Plugin 1.4.30
      Git plugin 4.0.0-rc

      Jenkins is using wrong commit SHA for pulling shared library when the build is triggered by pull request (we are using Bitbucket Pull Requests Builder plugin). The shared library is located in cm repository and the code is in frontend repo. Jenkins is using commit from frontend (9282bed3d923) to pull shared library from cm and ofc it doesn't find it in there. When the same build is restarted using Rebuild everything works as expected.

      <a href="https://bitbucket.org/myorg/frontend/pull-request/628">#628 DO-0 #time 10m #comment fix PR</a><a href="https://bitbucket.org/myorg/frontend/pull-request/628">#628 DO-0 #time 10m #comment fix PR</a>Checking out git git@bitbucket.org:myorg/frontend.git into /var/jenkins_home/workspace/build-frontend@script to read Jenkinsfileusing credential ******* > git rev-parse --is-inside-work-tree # timeout=10Fetching changes from the remote Git repository > git config remote.origin.url git@bitbucket.org:myorg/frontend.git # timeout=10Fetching upstream changes from git@bitbucket.org:myorg/frontend.git > git --version # timeout=10using GIT_SSH to set credentials  > git fetch --tags --progress git@bitbucket.org:myorg/frontend.git +refs/heads/*:refs/remotes/origin/* # timeout=10 > git rev-parse 9282bed3d923^{commit} # timeout=10 > git branch -a -v --no-abbrev --contains 9282bed3d923014e634f10e20655096b93e6c6fd # timeout=10Checking out Revision 9282bed3d923014e634f10e20655096b93e6c6fd (origin/Fix_PR) > git config core.sparsecheckout # timeout=10 > git checkout -f 9282bed3d923014e634f10e20655096b93e6c6fd # timeout=10Commit message: "DO-0 #time 10m #comment test" > git rev-list --no-walk 9282bed3d923014e634f10e20655096b93e6c6fd # timeout=10Resume disabled by user, switching to high-performance, low-durability mode.Loading library myorg-custom-libs@masterAttempting to resolve master from remote references... > git --version # timeout=10using GIT_SSH to set credentials  > git ls-remote git@bitbucket.org:myorg/cm.git # timeout=10Found match: refs/heads/master revision 6557c6a22c125115674db0c000d357519fa284a2using credential ******* > git rev-parse --is-inside-work-tree # timeout=10Fetching changes from the remote Git repository > git config remote.origin.url git@bitbucket.org:myorg/cm.git # timeout=10Fetching without tagsFetching upstream changes from git@bitbucket.org:myorg/cm.git > git --version # timeout=10using GIT_SSH to set credentials  > git fetch --no-tags --progress git@bitbucket.org:myorg/cm.git +refs/heads/*:refs/remotes/origin/* # timeout=10 > git rev-parse 9282bed3d923^{commit} # timeout=10hudson.plugins.git.GitException: Command "git rev-parse 9282bed3d923^{commit}" returned status code 128:stdout: 9282bed3d923^{commit}
      stderr: fatal: ambiguous argument '9282bed3d923^{commit}': unknown revision or path not in the working tree.Use '--' to separate paths from revisions, like this:'git <command> [<revision>...] -- [<file>...]'
       at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2318) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2248) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2244) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1777) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1789) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.revParse(CliGitAPIImpl.java:919) at hudson.plugins.git.GitAPI.revParse(GitAPI.java:316) at hudson.plugins.git.RevisionParameterAction.toRevision(RevisionParameterAction.java:98) at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:1059) at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1176) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:120) at org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever.lambda$doRetrieve$1(SCMSourceRetriever.java:147) at org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever.retrySCMOperation(SCMSourceRetriever.java:98) at org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever.doRetrieve(SCMSourceRetriever.java:146) at org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever.retrieve(SCMSourceRetriever.java:87) at org.jenkinsci.plugins.workflow.libs.LibraryAdder.retrieve(LibraryAdder.java:157) at org.jenkinsci.plugins.workflow.libs.LibraryAdder.add(LibraryAdder.java:138) at org.jenkinsci.plugins.workflow.libs.LibraryDecorator$1.call(LibraryDecorator.java:125) at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1065) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603) at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558) at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268) at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688) at groovy.lang.GroovyShell.parse(GroovyShell.java:700) at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.lambda$doParse$0(CpsGroovyShell.java:135) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:136) at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:132) at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127) at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:560) at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:521) at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:320) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:429) org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: Loading libraries failed
      1 error
       at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310) at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603) at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558) at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268) at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688) at groovy.lang.GroovyShell.parse(GroovyShell.java:700) at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.lambda$doParse$0(CpsGroovyShell.java:135) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:136) at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:132) at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127) at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:560) at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:521) at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:320) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:429) Finished: FAILURE Page generated: Mar 28, 2019 5:49:17 PM GMTREST APIJenkins ver. 2.164.1 

          [JENKINS-56801] Jenkins use wrong commit SHA when pulling shared library

          Mark Waite added a comment - - edited

          Can you check the data being sent by your Bitbucket webhook to see if it includes a parameter sha1 that is being assigned that value?

          If so, can you configure the Bitbucket webhook to not send the SHA1 as part of the webhook payload?

          There is a known bug that the git plugin mistakenly honors a SHA1 parameter value in places where it should ignore that value.

          I assume that the same behavior is seen with the released version of the git plugin (3.9.3) in addition to the release candidate.

          Mark Waite added a comment - - edited Can you check the data being sent by your Bitbucket webhook to see if it includes a parameter sha1 that is being assigned that value? If so, can you configure the Bitbucket webhook to not send the SHA1 as part of the webhook payload? There is a known bug that the git plugin mistakenly honors a SHA1 parameter value in places where it should ignore that value. I assume that the same behavior is seen with the released version of the git plugin (3.9.3) in addition to the release candidate.

          I have enabled logging for bitbucketpullrequestbuilder.bitbucketpullrequestbuilder and have retriggered PR from Bitbucket.
          In logs, i didn't find any SHA1 variable. Wrong commit here is 41d1da09d782bitbucketPRBuilder.log

          Yevhenii Tiutiunnyk added a comment - I have enabled logging for  bitbucketpullrequestbuilder.bitbucketpullrequestbuilder  and have retriggered PR from Bitbucket. In logs, i didn't find any SHA1 variable. Wrong commit here is 41d1da09d782 bitbucketPRBuilder.log

          Mark Waite added a comment -

          There is an entry in that log which reports hash which has the value of the sha1. That may be passed to the git plugin by the Jenkins bitbucket webhook handler as the sha1. Can Bitbucket be taught to not send the hash as part of its webhook?

          Mark Waite added a comment - There is an entry in that log which reports hash which has the value of the sha1. That may be passed to the git plugin by the Jenkins bitbucket webhook handler as the sha1. Can Bitbucket be taught to not send the hash as part of its webhook?

          I'm also encountering this with a PR job that uses a shared library, is there any recommendation?

          Trigger: BitBucketPullRequestBuilder
          Shared lib: folder level

          I'm not able to use Bitbucket web hooks due to our network config.

          Caty Kratzmann added a comment - I'm also encountering this with a PR job that uses a shared library, is there any recommendation? Trigger: BitBucketPullRequestBuilder Shared lib: folder level I'm not able to use Bitbucket web hooks due to our network config.

            Unassigned Unassigned
            evheniyt Yevhenii Tiutiunnyk
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: