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

TFS pull request verification build uses wrong branch

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • tfs-plugin
    • None
    • Jenkins 2.222.1, TFS plugin 5.157.1

      I configured a Jenkins job for TFS PR verification builds as described in the Git section of https://github.com/jenkinsci/tfs-plugin. The pull request commits are found on  branches named remotes/origin/pull/n/merge, so I added an additional branch specifier */merge to the Branches to build section of my Jenkins job definition.

      However, when the build runs, Git refuses to accept the commit from the merge branch with the error message skipping resolution of commit ..., since it originates from another repository but builds with the HEAD commit of the master branch instead of origin-pull/3/merge.

      Here is an excerpt of git log --oneline --graph --decorate --all:

      *   7fcad29 (origin-pull/3/merge) Merge pull request 3 from feature-one into master
      |\  
      | * 37f0c7d (origin/feature-one) Test
      * |   c7e2002 (HEAD, origin/master) Merged PR 2: change 5
      

      Here is the console log:

      Lightweight checkout support not available, falling back to full checkout.
      Checking out git http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git into /var/jenkins_home/workspace/pull-request-verification@script to read Jenkinsfile
      using credential c0c927b7-0a3a-4051-af13-91ef394cd497
       > git rev-parse --is-inside-work-tree # timeout=10
      Fetching changes from the remote Git repository
       > git config remote.origin.url http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git # timeout=10
      Fetching upstream changes from http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git
       > git --version # timeout=10
      using GIT_ASKPASS to set credentials 
       > git fetch --tags --progress -- http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git +refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/remotes/origin-pull/* # timeout=10
      skipping resolution of commit 7fcad293a558164c074986e0746a79eee02ba79d, since it originates from another repository
      Seen branch in repository origin-pull/2/merge
      Seen branch in repository origin-pull/3/merge
      Seen branch in repository origin/feature-one
      Seen branch in repository origin/master
      Seen 4 remote branches
       > git show-ref --tags -d # timeout=10
      Checking out Revision c7e2002a890151347a6bf38c5fbd423756149d1a (origin/master)
       > git config core.sparsecheckout # timeout=10
       > git checkout -f c7e2002a890151347a6bf38c5fbd423756149d1a # timeout=10
      Commit message: "Merged PR 2: change 5"
       > git rev-list --no-walk c7e2002a890151347a6bf38c5fbd423756149d1a # timeout=10
      Running in Durability level: MAX_SURVIVABILITY
      [Pipeline] Start of Pipeline
      [Pipeline] node
      Running on Jenkins in /var/jenkins_home/workspace/pull-request-verification
      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (Declarative: Checkout SCM)
      [Pipeline] checkout
      using credential c0c927b7-0a3a-4051-af13-91ef394cd497
       > git rev-parse --is-inside-work-tree # timeout=10
      Fetching changes from the remote Git repository
       > git config remote.origin.url http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git # timeout=10
      Fetching upstream changes from http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git
       > git --version # timeout=10
      using GIT_ASKPASS to set credentials 
       > git fetch --tags --progress -- http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git +refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/remotes/origin-pull/* # timeout=10
      skipping resolution of commit 7fcad293a558164c074986e0746a79eee02ba79d, since it originates from another repository
      Seen branch in repository origin-pull/2/merge
      Seen branch in repository origin-pull/3/merge
      Seen branch in repository origin/feature-one
      Seen branch in repository origin/master
      Seen 4 remote branches
       > git show-ref --tags -d # timeout=10
      Checking out Revision c7e2002a890151347a6bf38c5fbd423756149d1a (origin/master)
       > git config core.sparsecheckout # timeout=10
       > git checkout -f c7e2002a890151347a6bf38c5fbd423756149d1a # timeout=10
      Commit message: "Merged PR 2: change 5"
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] withEnv
      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (Build)
      [Pipeline] sh
      + cat README.md
      # Test Repository
      
      This repository has been set up for testing purposes only.
      
      This is another line added to trigger a build.
      And one more.
      
      This change has also been done on the feature-one branch.
      (First line removed)
      
      2020-04-08T13:23:58+00:00
      2020-04-08T13:27:16+00:00
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // withEnv
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: SUCCESS
      

          [JENKINS-61850] TFS pull request verification build uses wrong branch

          Gan Ainm added a comment - - edited

          Strangely, the build succeeds when the commit to be merged has been committed in the TFS Git repository itself. When the change is pushed into the TFS Git repository from a clone using a different user name and e-mail address, the pull request verification build fails as described above. Once user.name and user.email on the clone are set to be identical to the TFS Git repository, the pull request verification build after the push succeeds. This seems really strange!

          Another thing is that the build fails if it is triggered by a TFS branch policy validation build:

          Checking out git http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git into /var/jenkins_home/workspace/verification-build@script to read Jenkinsfile
          using credential c0c927b7-0a3a-4051-af13-91ef394cd497
           > git rev-parse --is-inside-work-tree # timeout=10
          Fetching changes from the remote Git repository
           > git config remote.origin.url http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git # timeout=10
          Fetching upstream changes from http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git
           > git --version # timeout=10
          using GIT_ASKPASS to set credentials 
           > git fetch --tags --progress -- http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git +refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/remotes/origin/pull/* # timeout=10
          skipping resolution of commit 03420e8348cfad32cb7916e537a83b4654fbce9b, since it originates from another repository
           > git rev-parse refs/remotes/origin/merge^{commit} # timeout=10
           > git rev-parse refs/remotes/origin/origin/merge^{commit} # timeout=10
           > git rev-parse origin/merge^{commit} # timeout=10
          ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
          ERROR: Maximum checkout retry attempts reached, aborting
          Finished: FAILURE
          

          However, it succeeds when it is triggered by a Jenkins Service Hook in TFS:

          Checking out git http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git into /var/jenkins_home/workspace/verification-build@script to read Jenkinsfile
          using credential c0c927b7-0a3a-4051-af13-91ef394cd497
           > git rev-parse --is-inside-work-tree # timeout=10
          Fetching changes from the remote Git repository
           > git config remote.origin.url http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git # timeout=10
          Fetching upstream changes from http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git
           > git --version # timeout=10
          using GIT_ASKPASS to set credentials 
           > git fetch --tags --progress -- http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git +refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/remotes/origin/pull/* # timeout=10
           > git rev-parse c607f67f5388726e9b8aa8f04768214e8f5ba5c4^{commit} # timeout=10
           > git branch -a -v --no-abbrev --contains c607f67f5388726e9b8aa8f04768214e8f5ba5c4 # timeout=10
          Checking out Revision c607f67f5388726e9b8aa8f04768214e8f5ba5c4 (origin/pull/19/merge)
           > git config core.sparsecheckout # timeout=10
           > git checkout -f c607f67f5388726e9b8aa8f04768214e8f5ba5c4 # timeout=10
          Commit message: "Merge pull request 19 from feature-one into master"
          First time build. Skipping changelog.
          Running in Durability level: MAX_SURVIVABILITY
          [Pipeline] Start of Pipeline
          [Pipeline] node
          Running on Jenkins in /var/jenkins_home/workspace/verification-build
          [Pipeline] {
          [Pipeline] stage
          [Pipeline] { (Declarative: Checkout SCM)
          [Pipeline] checkout
          using credential c0c927b7-0a3a-4051-af13-91ef394cd497
           > git rev-parse --is-inside-work-tree # timeout=10
          Fetching changes from the remote Git repository
           > git config remote.origin.url http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git # timeout=10
          Fetching upstream changes from http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git
           > git --version # timeout=10
          using GIT_ASKPASS to set credentials 
           > git fetch --tags --progress -- http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git +refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/remotes/origin/pull/* # timeout=10
           > git rev-parse c607f67f5388726e9b8aa8f04768214e8f5ba5c4^{commit} # timeout=10
           > git branch -a -v --no-abbrev --contains c607f67f5388726e9b8aa8f04768214e8f5ba5c4 # timeout=10
          Checking out Revision c607f67f5388726e9b8aa8f04768214e8f5ba5c4 (origin/pull/19/merge)
           > git config core.sparsecheckout # timeout=10
           > git checkout -f c607f67f5388726e9b8aa8f04768214e8f5ba5c4 # timeout=10
          Commit message: "Merge pull request 19 from feature-one into master"
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] withEnv
          [Pipeline] {
          [Pipeline] stage
          [Pipeline] { (Build)
          [Pipeline] sh
          + cat README.md
          # Test Repository
          
          This repository has been set up for testing purposes only.
          
          This is another line added to trigger a build.
          And one more.
          
          This change has also been done on the feature-one branch.
          (First line removed)
          
          Last entry on feature-one.
          2020-04-16T15:08:13+00:00
          TGIF!!!
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] }
          [Pipeline] // withEnv
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          Finished: SUCCESS
          

          The Git log output after the successful verification build triggered by the service hook (commit c607f67) the failed branch policy build (pull request abandoned after failure) should have built commit 03420e8:

          *   c607f67 (HEAD, origin/pull/19/merge) Merge pull request 19 from feature-one into master
          |\  
          | | *   03420e8 (origin/pull/18/merge) Merge pull request 18 from feature-one into master
          | | |\  
          | |/ /  
          |/| /   
          | |/    
          | | *   8d28981 (origin/pull/17/merge) Merge pull request 17 from feature-one into master
          | | |\  
          | |/ /  
          |/| /   
          | |/    
          | | *   7836f47 (origin/pull/16/merge) Merge pull request 16 from feature-one into master
          | | |\  
          | |/ /  
          |/| /   
          | |/    
          | * e7d5c43 (origin/feature-one) Thank God it's friday
          

          The error message is produced by the Jenkins Git plugin, so I assume that is the source of the strange behavior.

          Gan Ainm added a comment - - edited Strangely, the build succeeds when the commit to be merged has been committed in the TFS Git repository itself. When the change is pushed into the TFS Git repository from a clone using a different user name and e-mail address, the pull request verification build fails as described above. Once user.name and user.email on the clone are set to be identical to the TFS Git repository, the pull request verification build after the push succeeds. This seems really strange! Another thing is that the build fails if it is triggered by a TFS branch policy validation build: Checking out git http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git into /var/jenkins_home/workspace/verification-build@script to read Jenkinsfile using credential c0c927b7-0a3a-4051-af13-91ef394cd497 > git rev-parse --is-inside-work-tree # timeout=10 Fetching changes from the remote Git repository > git config remote.origin.url http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git # timeout=10 Fetching upstream changes from http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git > git --version # timeout=10 using GIT_ASKPASS to set credentials > git fetch --tags --progress -- http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git +refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/remotes/origin/pull/* # timeout=10 skipping resolution of commit 03420e8348cfad32cb7916e537a83b4654fbce9b, since it originates from another repository > git rev-parse refs/remotes/origin/merge^{commit} # timeout=10 > git rev-parse refs/remotes/origin/origin/merge^{commit} # timeout=10 > git rev-parse origin/merge^{commit} # timeout=10 ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job. ERROR: Maximum checkout retry attempts reached, aborting Finished: FAILURE However, it succeeds when it is triggered by a Jenkins Service Hook in TFS: Checking out git http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git into /var/jenkins_home/workspace/verification-build@script to read Jenkinsfile using credential c0c927b7-0a3a-4051-af13-91ef394cd497 > git rev-parse --is-inside-work-tree # timeout=10 Fetching changes from the remote Git repository > git config remote.origin.url http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git # timeout=10 Fetching upstream changes from http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git > git --version # timeout=10 using GIT_ASKPASS to set credentials > git fetch --tags --progress -- http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git +refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/remotes/origin/pull/* # timeout=10 > git rev-parse c607f67f5388726e9b8aa8f04768214e8f5ba5c4^{commit} # timeout=10 > git branch -a -v --no-abbrev --contains c607f67f5388726e9b8aa8f04768214e8f5ba5c4 # timeout=10 Checking out Revision c607f67f5388726e9b8aa8f04768214e8f5ba5c4 (origin/pull/19/merge) > git config core.sparsecheckout # timeout=10 > git checkout -f c607f67f5388726e9b8aa8f04768214e8f5ba5c4 # timeout=10 Commit message: "Merge pull request 19 from feature-one into master" First time build. Skipping changelog. Running in Durability level: MAX_SURVIVABILITY [Pipeline] Start of Pipeline [Pipeline] node Running on Jenkins in /var/jenkins_home/workspace/verification-build [Pipeline] { [Pipeline] stage [Pipeline] { (Declarative: Checkout SCM) [Pipeline] checkout using credential c0c927b7-0a3a-4051-af13-91ef394cd497 > git rev-parse --is-inside-work-tree # timeout=10 Fetching changes from the remote Git repository > git config remote.origin.url http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git # timeout=10 Fetching upstream changes from http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git > git --version # timeout=10 using GIT_ASKPASS to set credentials > git fetch --tags --progress -- http://10.0.2.2:8080/tfs/DefaultCollection/Jenkins-Git-Test/_git/testit.git +refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/remotes/origin/pull/* # timeout=10 > git rev-parse c607f67f5388726e9b8aa8f04768214e8f5ba5c4^{commit} # timeout=10 > git branch -a -v --no-abbrev --contains c607f67f5388726e9b8aa8f04768214e8f5ba5c4 # timeout=10 Checking out Revision c607f67f5388726e9b8aa8f04768214e8f5ba5c4 (origin/pull/19/merge) > git config core.sparsecheckout # timeout=10 > git checkout -f c607f67f5388726e9b8aa8f04768214e8f5ba5c4 # timeout=10 Commit message: "Merge pull request 19 from feature-one into master" [Pipeline] } [Pipeline] // stage [Pipeline] withEnv [Pipeline] { [Pipeline] stage [Pipeline] { (Build) [Pipeline] sh + cat README.md # Test Repository This repository has been set up for testing purposes only. This is another line added to trigger a build. And one more. This change has also been done on the feature-one branch. (First line removed) Last entry on feature-one. 2020-04-16T15:08:13+00:00 TGIF!!! [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline Finished: SUCCESS The Git log output after the successful verification build triggered by the service hook (commit c607f67) the failed branch policy build (pull request abandoned after failure) should have built commit 03420e8: * c607f67 (HEAD, origin/pull/19/merge) Merge pull request 19 from feature-one into master |\ | | * 03420e8 (origin/pull/18/merge) Merge pull request 18 from feature-one into master | | |\ | |/ / |/| / | |/ | | * 8d28981 (origin/pull/17/merge) Merge pull request 17 from feature-one into master | | |\ | |/ / |/| / | |/ | | * 7836f47 (origin/pull/16/merge) Merge pull request 16 from feature-one into master | | |\ | |/ / |/| / | |/ | * e7d5c43 (origin/feature-one) Thank God it's friday The error message is produced by the Jenkins Git plugin, so I assume that is the source of the strange behavior.

          Gan Ainm added a comment - - edited

          I retried the scenario with different settings and it worked. Obviously, the documentation at https://github.com/jenkinsci/tfs-plugin gives wrong examples for Jenkins' pull request verification build configuration:

          • The refspec must be
            +refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/remotes/origin/pull/*
            

            instead of

            +refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/remotes/origin-pull/*
            
          • The branch specifier must be
            **/merge

            instead of

            */master

          The documentation needs an update.

          Gan Ainm added a comment - - edited I retried the scenario with different settings and it worked. Obviously, the documentation at https://github.com/jenkinsci/tfs-plugin gives wrong examples for Jenkins' pull request verification build configuration: The refspec must be +refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/remotes/origin/pull/* instead of +refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/remotes/origin-pull/* The branch specifier must be **/merge instead of */master The documentation needs an update.

          Ian Williams added a comment -

          redsolo is no longer maintaining plugin; unassigned issues

          Ian Williams added a comment - redsolo is no longer maintaining plugin; unassigned issues

          I hope you have configured this from azure to Jenkins using tfs plugin. please refer https://docs.microsoft.com/en-us/azure/devops/service-hooks/events?view=azure-devops . search for Event ID: git.push . the url should be https://dev.azure.com  . this is the payload.

          if you give this url in your jenkins git repo url in the pipeline, this works. I have verified

          vivek rajendran added a comment - I hope you have configured this from azure to Jenkins using tfs plugin. please refer https://docs.microsoft.com/en-us/azure/devops/service-hooks/events?view=azure-devops  . search for Event ID:  git.push . the url should be https://dev.azure.com   . this is the payload. if you give this url in your jenkins git repo url in the pipeline, this works. I have verified

            Unassigned Unassigned
            ganainm Gan Ainm
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: