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

No build created on PR creation in mulitbranch

      Update 06-03-2023
      Comment of nicram has a reproducing steps. That's the problem I see also in Jenkins.


      I'm testing that a Pull request creation triggers a build on jenkins in a multi branch pipeline, but no build is started. But pipeline and freestyle jobs it works.

      In the "Multibranch Pipeline Events" log I see the event:

      [Wed Dec 22 16:28:25 CET 2021] Received com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookConsumer$BitbucketSCMHeadPullRequestEvent CREATED event from REPO with timestamp Wed Dec 22 16:28:25 CET 2021
       > C:\Program Files\Git\cmd\git.exe rev-parse --resolve-git-dir D:\jenkins_home\caches\git-b61b7506000694e1d0bb86961f485eba\.git # timeout=10
      Setting origin to https://bitbucket.mcrsota.nl/scm/crs-web/REPO.git
       > C:\Program Files\Git\cmd\git.exe config remote.origin.url https://bitbucket.{server}.nl/scm/crs-web/mijncaressionic.git # timeout=10
      Fetching & pruning origin...
      Listing remote references...
       > C:\Program Files\Git\cmd\git.exe config --get remote.origin.url # timeout=10
       > C:\Program Files\Git\cmd\git.exe --version # timeout=10
       > git --version # 'git version 2.34.1.windows.1'
      using GIT_ASKPASS to set credentials BitBucket Service Account for Jenkins
       > C:\Program Files\Git\cmd\git.exe ls-remote -h -- https://bitbucket.{server}.nl/scm/crs-web/REPO.git # timeout=10
      Fetching upstream changes from origin
       > C:\Program Files\Git\cmd\git.exe config --get remote.origin.url # timeout=10
      using GIT_ASKPASS to set credentials BitBucket Service Account for Jenkins
       > C:\Program Files\Git\cmd\git.exe fetch --tags --force --progress --prune -- origin +refs/heads/*:refs/remotes/origin/* # timeout=10
      Checking branches...
      Processed 20 branches
      [Wed Dec 22 16:28:28 CET 2021] com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookConsumer$BitbucketSCMHeadPullRequestEvent CREATED event from REPO with timestamp Wed Dec 22 16:28:25 CET 2021 processed in 2.4 sec
      

      On Pr update the build is run:

      [Wed Dec 22 17:22:40 CET 2021] Received com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookConsumer$BitbucketSCMHeadPullRequestEvent UPDATED event from REPO with timestamp Wed Dec 22 17:22:31 CET 2021
       > C:\Program Files\Git\cmd\git.exe rev-parse --resolve-git-dir D:\jenkins_home\caches\git-b61b7506000694e1d0bb86961f485eba\.git # timeout=10
      Setting origin to https://bitbucket.{server}.nl/scm/crs-web/REPO.git
       > C:\Program Files\Git\cmd\git.exe config remote.origin.url https://bitbucket.{server}.nl/scm/crs-web/REPO.git # timeout=10
      Fetching & pruning origin...
      Listing remote references...
       > C:\Program Files\Git\cmd\git.exe config --get remote.origin.url # timeout=10
       > C:\Program Files\Git\cmd\git.exe --version # timeout=10
       > git --version # 'git version 2.34.1.windows.1'
      using GIT_ASKPASS to set credentials BitBucket Service Account for Jenkins
       > C:\Program Files\Git\cmd\git.exe ls-remote -h -- https://bitbucket.{server}.nl/scm/crs-web/REPO.git # timeout=10
      Fetching upstream changes from origin
       > C:\Program Files\Git\cmd\git.exe config --get remote.origin.url # timeout=10
      using GIT_ASKPASS to set credentials BitBucket Service Account for Jenkins
       > C:\Program Files\Git\cmd\git.exe fetch --tags --force --progress --prune -- origin +refs/heads/*:refs/remotes/origin/* # timeout=10
      Checking branches...
        Checking branch feature/CRS-94885-Integratie-feature-builds-van-de-11-Jenkins-pipelines-met-Bitbucket-en-Sonar
            ‘Jenkinsfile’ found
          Met criteria
      Changes detected: feature/CRS-94885-Integratie-feature-builds-van-de-11-Jenkins-pipelines-met-Bitbucket-en-Sonar (e13c30e47cdaa617777bdc41a5fa3e4ede7e1024 → 1a2bc0ab0796c2695a1e2675dc95483e6a2d77ff)
      Scheduled build for branch: feature/CRS-94885-Integratie-feature-builds-van-de-11-Jenkins-pipelines-met-Bitbucket-en-Sonar
      Processed 19 branches (query complete)
      [Wed Dec 22 17:22:42 CET 2021] com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookConsumer$BitbucketSCMHeadPullRequestEvent UPDATED event from REPO with timestamp Wed Dec 22 17:22:31 CET 2021 processed in 2.6 sec
      

      Pipeline settings:

      for now I only test one branch, but without that is also doesn't work.
      The branch where I make the pull request from exist on the branches page.

      Do I something wrong?

          [JENKINS-67437] No build created on PR creation in mulitbranch

          Hi Marco, thanks for the report and apologies for not getting back to you sooner.

          I attempted to replicate this locally (using your branch name and selector) and upon creating a PR and pushing a change, the build was triggering as expected.
          Can you clarify exactly what your issue is? It sounds like the build is not triggering upon making a change to a PR. The PR update logs you provide look more like the multibranch pipeline scan logs (which show your branch being picked up as expected).
          If the build isn't being triggered, could you possibly share access logs from Bitbucket and your Jenkins logs?

          Martin Henschke added a comment - Hi Marco, thanks for the report and apologies for not getting back to you sooner. I attempted to replicate this locally (using your branch name and selector) and upon creating a PR and pushing a change, the build was triggering as expected. Can you clarify exactly what your issue is? It sounds like the build is not triggering upon making a change to a PR. The PR update logs you provide look more like the multibranch pipeline scan logs (which show your branch being picked up as expected). If the build isn't being triggered, could you possibly share access logs from Bitbucket and your Jenkins logs?

          Marco van Munster added a comment - - edited

          Do you mean that build is started after PR creation or push a change. So 2 build are triggered. And not 1 build after creation and updating the PR. I think you mean the first in your comment, I will test it again and check I have more log information why build is not started in my case.

          First I misread your comment, below how I expected how PR feature works
          I expect that there is also build started on PR creation without a change pushed in GIT, because mostly I'm already finished with development when the PR is created in bitbucket. The use case is that I only have to build a feature branch on creating a Pr or updating the PR by pushing a new commit to branch of the PR.
          But maybe my assumption about how the PR creation trigger should work is not correct.

          Marco van Munster added a comment - - edited Do you mean that build is started after PR creation or push a change. So 2 build are triggered. And not 1 build after creation and updating the PR. I think you mean the first in your comment, I will test it again and check I have more log information why build is not started in my case. First I misread your comment, below how I expected how PR feature works I expect that there is also build started on PR creation without a change pushed in GIT, because mostly I'm already finished with development when the PR is created in bitbucket. The use case is that I only have to build a feature branch on creating a Pr or updating the PR by pushing a new commit to branch of the PR. But maybe my assumption about how the PR creation trigger should work is not correct.

          Marco van Munster added a comment - - edited

          I tested again, first it works as expected, but when I add option in the screenshot, no build is started after PR creation

          Multibranch Pipeline Events

          I don't remember if I added this option month ago, but I added that because otherwise also builds are started because of:

          We use this option to cleanup deleted PR/branches, otherwise these where never cleanup in our case.

          Also without "Suppress automatic SCM triggering" the buil is started with reason: "Branch indexing

          So when I use the check `changeRequest` in a jenkinsfile, the stage is not run

          stage('Sonar') {
             when {
                 changeRequest()        
              }
          }
          

          Marco van Munster added a comment - - edited I tested again, first it works as expected, but when I add option in the screenshot, no build is started after PR creation Multibranch Pipeline Events I don't remember if I added this option month ago, but I added that because otherwise also builds are started because of: We use this option to cleanup deleted PR/branches, otherwise these where never cleanup in our case. Also without "Suppress automatic SCM triggering" the buil is started with reason: "Branch indexing So when I use the check `changeRequest` in a jenkinsfile, the stage is not run stage( 'Sonar' ) { when { changeRequest() } }

          when { changeRequest() } causes ChangeRequestConditional to check the CHANGE_ID environment variable. In other types of multibranch projects, BranchNameContributor adds the CHANGE_ID environment variable if the SCMHead of the branch is a ChangeRequestSCMHead. However, Bitbucket Server Integration does not support ChangeRequestSCMHead or ChangeRequestSCMHead2 yet (JENKINS-66581). So, I think that will have to be implemented and then when { changeRequest() } will work.

          Alternatively, I imagine Bitbucket Server Integration could be changed to add the CHANGE_ID environment variable on its own. That however doesn't really seem easier than implementing ChangeRequestSCMHead2 properly.

          Kalle Niemitalo added a comment - when { changeRequest() } causes ChangeRequestConditional to check the CHANGE_ID environment variable . In other types of multibranch projects, BranchNameContributor adds the CHANGE_ID environment variable if the SCMHead of the branch is a ChangeRequestSCMHead. However, Bitbucket Server Integration does not support ChangeRequestSCMHead or ChangeRequestSCMHead2 yet ( JENKINS-66581 ). So, I think that will have to be implemented and then when { changeRequest() } will work. Alternatively, I imagine Bitbucket Server Integration could be changed to add the CHANGE_ID environment variable on its own. That however doesn't really seem easier than implementing ChangeRequestSCMHead2 properly.

          Marcin Romanowski added a comment - - edited

          Hi,
          I have the same issue. Problem is when I'm creating PR first time after commit. I was listening with tcpdump and to jenkins data are provided with payload but "multibranch pipeline events" stay quiet.
          When I remove PR then jenkins catches REMOVE event and after this when I create PR this is now catched.

          [Thu Sep 29 15:44:23 UTC 2022] com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookConsumer$BitbucketSCMHeadEvent UPDATED event from jenkins with timestamp Thu Sep 29 15:44:22 UTC 2022 processed in 0.44 sec
          [Thu Sep 29 15:46:23 UTC 2022] Received com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookConsumer$BitbucketSCMHeadPullRequestEvent REMOVED event from jenkins with timestamp Thu Sep 29 15:46:23 UTC 2022
          [Thu Sep 29 15:46:23 UTC 2022] com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookConsumer$BitbucketSCMHeadPullRequestEvent REMOVED event from jenkins with timestamp Thu Sep 29 15:46:23 UTC 2022 processed in 22 ms
          [Thu Sep 29 15:46:32 UTC 2022] Received com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookConsumer$BitbucketSCMHeadPullRequestEvent CREATED event from jenkins with timestamp Thu Sep 29 15:46:32 UTC 2022
           > git rev-parse --resolve-git-dir /var/jenkins_home/caches/git-1395b67b48a90417b3cd37a28c6618e3/.git # timeout=10
          Setting origin to http://bitbucket:7990/scm/jen/jenkins.git
           > git config remote.origin.url http://bitbucket:7990/scm/jen/jenkins.git # timeout=10
          Fetching & pruning origin...
          Listing remote references...
           > git config --get remote.origin.url # timeout=10
           > git --version # timeout=10
           > git --version # 'git version 2.30.2'
          using GIT_ASKPASS to set credentials 
           > git ls-remote -h -- http://bitbucket:7990/scm/jen/jenkins.git # timeout=10
          Fetching upstream changes from origin
           > git config --get remote.origin.url # timeout=10
          using GIT_ASKPASS to set credentials 
           > git fetch --tags --force --progress --prune -- origin +refs/heads/*:refs/remotes/origin/* # timeout=10
          Checking branches...
            Checking branch develop
                ‘Jenkinsfile’ found
              Met criteria
          Branch reopened: develop (96c0d5e6d1daf85aff1faeb3d4efe00bdd229bb5)
          Scheduled build for branch: develop
          Processed 1 branches (query complete)
          [Thu Sep 29 15:46:32 UTC 2022] com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookConsumer$BitbucketSCMHeadPullRequestEvent CREATED event from jenkins with timestamp Thu Sep 29 15:46:32 UTC 2022 processed in 0.52 sec 

          Now I can remove and create PR angain and all is catched as expected. 
          But when I delete PR, make some changes in code, create new commit in source brand and create new PR (first PR after commit) this is not chatched by jenkins. Removing and creating PR again solves this.

          My test environment is in docker

          docker network create jenkinstest
          docker run --name jenkins --rm --detach --network jenkinstest --env DOCKER_CERT_PATH=/certs/client --env DOCKER_TLS_VERIFY=1 --publish 8080:8080 --publish 50000:50000 --volume jenkins-data:/var/jenkins_home jenkins/jenkins:2.361.1-lts-jdk11
          docker run --rm --detach -v bitbucketVolume:/var/atlassian/application-data/bitbucket --name="bitbucket" --network jenkinstest -p 7990:7990 -p 7999:7999 atlassian/bitbucket echo "127.0.0.1 bitbucket jenkins" >> /etc/hosts 

           

          I'v noticed that this happens when both pushes and pull request triggers are set. 
          When I set only "pull requeste" workes for every time 

           

           

          Marcin Romanowski added a comment - - edited Hi, I have the same issue. Problem is when I'm creating PR first time after commit. I was listening with tcpdump and to jenkins data are provided with payload but "multibranch pipeline events" stay quiet. When I remove PR then jenkins catches REMOVE event and after this when I create PR this is now catched. [Thu Sep 29 15:44:23 UTC 2022] com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookConsumer$BitbucketSCMHeadEvent UPDATED event from jenkins with timestamp Thu Sep 29 15:44:22 UTC 2022 processed in 0.44 sec [Thu Sep 29 15:46:23 UTC 2022] Received com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookConsumer$BitbucketSCMHeadPullRequestEvent REMOVED event from jenkins with timestamp Thu Sep 29 15:46:23 UTC 2022 [Thu Sep 29 15:46:23 UTC 2022] com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookConsumer$BitbucketSCMHeadPullRequestEvent REMOVED event from jenkins with timestamp Thu Sep 29 15:46:23 UTC 2022 processed in 22 ms [Thu Sep 29 15:46:32 UTC 2022] Received com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookConsumer$BitbucketSCMHeadPullRequestEvent CREATED event from jenkins with timestamp Thu Sep 29 15:46:32 UTC 2022 > git rev-parse --resolve-git-dir / var /jenkins_home/caches/git-1395b67b48a90417b3cd37a28c6618e3/.git # timeout=10 Setting origin to http: //bitbucket:7990/scm/jen/jenkins.git > git config remote.origin.url http: //bitbucket:7990/scm/jen/jenkins.git # timeout=10 Fetching & pruning origin... Listing remote references... > git config --get remote.origin.url # timeout=10 > git --version # timeout=10 > git --version # 'git version 2.30.2' using GIT_ASKPASS to set credentials > git ls-remote -h -- http: //bitbucket:7990/scm/jen/jenkins.git # timeout=10 Fetching upstream changes from origin > git config --get remote.origin.url # timeout=10 using GIT_ASKPASS to set credentials > git fetch --tags --force --progress --prune -- origin +refs/heads/*:refs/remotes/origin/* # timeout=10 Checking branches... Checking branch develop ‘Jenkinsfile’ found Met criteria Branch reopened: develop (96c0d5e6d1daf85aff1faeb3d4efe00bdd229bb5) Scheduled build for branch: develop Processed 1 branches (query complete) [Thu Sep 29 15:46:32 UTC 2022] com.atlassian.bitbucket.jenkins.internal.trigger.BitbucketWebhookConsumer$BitbucketSCMHeadPullRequestEvent CREATED event from jenkins with timestamp Thu Sep 29 15:46:32 UTC 2022 processed in 0.52 sec Now I can remove and create PR angain and all is catched as expected.  But when I delete PR, make some changes in code, create new commit in source brand and create new PR (first PR after commit) this is not chatched by jenkins. Removing and creating PR again solves this. My test environment is in docker docker network create jenkinstest docker run --name jenkins --rm --detach --network jenkinstest --env DOCKER_CERT_PATH=/certs/client --env DOCKER_TLS_VERIFY=1 --publish 8080:8080 --publish 50000:50000 --volume jenkins-data:/ var /jenkins_home jenkins/jenkins:2.361.1-lts-jdk11 docker run --rm --detach -v bitbucketVolume:/ var /atlassian/application-data/bitbucket --name= "bitbucket" --network jenkinstest -p 7990:7990 -p 7999:7999 atlassian/bitbucket echo "127.0.0.1 bitbucket jenkins" >> /etc/hosts   I'v noticed  that this happens when both pushes and pull request triggers are set.  When I set only "pull requeste" workes for every time     

          Sam Gleske added a comment -

          This bug report duplicates JENKINS-66581.

          Sam Gleske added a comment - This bug report duplicates JENKINS-66581 .

            Unassigned Unassigned
            marco_mybit Marco van Munster
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: