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

Missing builds status connection with Pull Requests

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Major Major
    • None
    • OS Ubuntu 24.04.1 LTS
      The same issue was reproduced on OS Ubuntu 22.04.5 LTS

      Jenkins version 2.490
      Bitbucket Branch Source Plugin 933.0.2

      Bitbucket Cloud

      We used the Bitbucket Cloud + Jenkins server and I have an issue with the Pull Requests build status

      On the bitbucket Cloud side, we use the Branch restrictions rules to check the Minimum number of successful builds. This allows us to make sure we merge only stable code to our Stage environment. Since the last two weeks, the build status fully has worked only for branch tabs in Bitbucket Cloud and partly for PR tabs in Bitbucket Cloud.

      Bitbucket configuration:

      1. Create a user.
      2. Create an app password.
      3. Add user to Repo.
      4. Create Webhhok in Repo https://jenkins-url/bitbucket-scmsource-hook/notify
      5. Configure Branch restrictions for example for stage branch
        5.1 Minimum number of successful builds for the last commit with no failed builds and no in-progress builds -1
        5.2 Prevent a merge with unresolved merge checks

      Jenkins configuration

      1. Add credentials with Username and App password to the credentials
      2. Install the plugin Bitbucket Branch Source
      3. Go to Jenkins system setting Bitbucket Endpoints
        3.1 Use Manage hooks
        3.2 Chose stored credentials from the step 1
        3.3 Use the Jenkins URL in the Custom Jenkins Root URL field.

      Jenkins Multibranch pipeline project

      1. Use Branch Sources - Bitbucket
      2. Use the same credentials from (Jenkins configuration step 1)
      3. Configure repo
      4. Run any build for any branch
      5. Create PR from the branch that was built in the Multibranch pipeline to the stage branch

      If we go to the branches tab that was built we will see the connection to the Multibranch pipeline project - specific build

      But if we go to the PR tab and check the same we see the built status icon but without connection to Builds

      When I click on the Builds icon I don't see anything and as a result, I can't merge the PR because the build result is successful but without a connection to the specific build

      I have checked the webhook logs and it looks also fine

          [JENKINS-75042] Missing builds status connection with Pull Requests

          Nikolas Falco added a comment - - edited

          I can not reproduce the issue. Our production works and show only the build status related to the PR (that have refname = null)

          Hi, I would ask to you to call this API for your PR
          https://api.bitbucket.org/2.0/repositories/<owner>/<repo_slug>/pullrequests/<PR-id>/statuses using the app password (also in postaman)
          I would to see the response. In particular how many values are there, in particular key/state/refname/commit-hash.

          If no result than use this other call to the latest commit of the PR:

          https://api.bitbucket.org/2.0/repositories/<owner>/<repo_slug>/commit/<last-commit-hash>/statuses

          Nikolas Falco added a comment - - edited I can not reproduce the issue. Our production works and show only the build status related to the PR (that have refname = null) Hi, I would ask to you to call this API for your PR https://api.bitbucket.org/2.0/repositories/ <owner>/<repo_slug>/pullrequests/<PR-id>/statuses using the app password (also in postaman) I would to see the response. In particular how many values are there, in particular key/state/refname/commit-hash. If no result than use this other call to the latest commit of the PR: https://api.bitbucket.org/2.0/repositories/ <owner>/<repo_slug>/commit/<last-commit-hash>/statuses

          Pavlo added a comment -

          nfalco I have sent API call to  https://api.bitbucket.org/2.0/repositories/<owner>/<repo_slug>/pullrequests/<PR-id>/statuses

          This is the result: 

          {"values": [], "pagelen": 30, "size": 0, "page": 1} 

          After that I have used API call to 
          https://api.bitbucket.org/2.0/repositories/<owner>/<repo_slug>/commit/<last-commit-hash>/statuses

          I have replaced the text in the response: 
          Jenkins URL 
          Repo name
          commit-hash
          Owner

          This is a test PR so I have there only one commit

          {
              "values": [
                  {
                      "key": "ddf9e9ace...",
                      "type": "build",
                      "state": "SUCCESSFUL",
                      "name": "test » pavlo-testing2 #7",
                      "refname": "refs/heads/pavlo-testing2",
                      "commit": {
                          "hash": "commit-hash",
                          "links": {
                              "self": {
                                  "href": "https://api.bitbucket.org/2.0/repositories/owner/repo/commit/commit-hash"
                              },
                              "html": {
                                  "href": "https://bitbucket.org/owner/repo/commits/commit-hash"
                              }
                          },
                          "type": "commit"
                      },
                      "url": "https://jenkins_url/job/test/job/pavlo-testing2/7/display/redirect",
                      "repository": {
                          "type": "repository",
                          "full_name": "owner/repo",
                          "links": {
                              "self": {
                                  "href": "https://api.bitbucket.org/2.0/repositories/owner/repo"
                              },
                              "html": {
                                  "href": "https://bitbucket.org/owner/repo"
                              },
                              "avatar": {
                                  "href": "https://bytebucket.org/ravatar/%7Bc62b3a64-3697-40a5-94ec-2796afa25000%7D?ts=default"
                              }
                          },
                          "name": "Repo:name",
                          "uuid": "{c62b3a64-3697-40a5-94ec-2796afa25000}"
                      },
                      "description": "This commit looks good.",
                      "created_on": "2024-12-13T23:29:47.053768+00:00",
                      "updated_on": "2024-12-13T23:39:56.610263+00:00",
                      "links": {
                          "self": {
                              "href": "https://api.bitbucket.org/2.0/repositories/owner/repo/commit/commit-hash/statuses/build/ddf9e9aceced1716fe9589128812e304"
                          },
                          "commit": {
                              "href": "https://api.bitbucket.org/2.0/repositories/owner/repo/commit/commit-hash"
                          }
                      }
                  },
                  {
                      "key": "c386732272563dc5ec49d201a7f99b37",
                      "type": "build",
                      "state": "SUCCESSFUL",
                      "name": "Multibranch-Partners » pavlo-testing2 #3",
                      "refname": "refs/heads/pavlo-testing2",
                      "commit": {
                          "hash": "commit-hash",
                          "links": {
                              "self": {
                                  "href": "https://api.bitbucket.org/2.0/repositories/owner/repo/commit/commit-hash"
                              },
                              "html": {
                                  "href": "https://bitbucket.org/owner/repo/commits/commit-hash"
                              }
                          },
                          "type": "commit"
                      },
                      "url": "https://jenkins_url/job/Multibranch-Partners/job/pavlo-testing2/3/display/redirect",
                      "repository": {
                          "type": "repository",
                          "full_name": "owner/repo",
                          "links": {
                              "self": {
                                  "href": "https://api.bitbucket.org/2.0/repositories/owner/repo"
                              },
                              "html": {
                                  "href": "https://bitbucket.org/owner/repo"
                              },
                              "avatar": {
                                  "href": "https://bytebucket.org/ravatar/%7Bc62b3a64-3697-40a5-94ec-2796afa25000%7D?ts=default"
                              }
                          },
                          "name": "Repo:name",
                          "uuid": "{c62b3a64-3697-40a5-94ec-2796afa25000}"
                      },
                      "description": "This commit looks good.",
                      "created_on": "2024-12-13T23:29:47.520499+00:00",
                      "updated_on": "2024-12-19T09:55:09.780075+00:00",
                      "links": {
                          "self": {
                              "href": "https://api.bitbucket.org/2.0/repositories/owner/repo/commit/commit-hash/statuses/build/c386732272563dc5ec49d201a7f99b37"
                          },
                          "commit": {
                              "href": "https://api.bitbucket.org/2.0/repositories/owner/repo/commit/commit-hash"
                          }
                      }
                  }
              ],
              "pagelen": 10,
              "size": 2,
              "page": 1
          } 

          When I sent the API call to   https://api.bitbucket.org/2.0/repositories/<owner>/<repo_slug>/pullrequests/<PR-id> 
          I see the information about the PR.
           
          Do you have any idea what the issue might be? 
          and thank you for your help I appreciate it. 

          Pavlo added a comment - nfalco I have sent API call to   https://api.bitbucket.org/2.0/repositories/ <owner>/<repo_slug>/pullrequests/<PR-id>/statuses This is the result:  { "values" : [], "pagelen" : 30, "size" : 0, "page" : 1} After that I have used API call to  https://api.bitbucket.org/2.0/repositories/ <owner>/<repo_slug>/commit/<last-commit-hash>/statuses I have replaced the text in the response:  Jenkins URL  Repo name commit-hash Owner This is a test PR so I have there only one commit {     "values" : [         {             "key" : "ddf9e9ace..." ,             "type" : "build" ,             "state" : "SUCCESSFUL" ,             "name" : "test » pavlo-testing2 #7" ,             "refname" : "refs/heads/pavlo-testing2" ,             "commit" : {                 "hash" : "commit-hash" ,                 "links" : {                     "self" : {                         "href" : "https: //api.bitbucket.org/2.0/repositories/owner/repo/commit/commit-hash"                     },                     "html" : {                         "href" : "https: //bitbucket.org/owner/repo/commits/commit-hash"                     }                 },                 "type" : "commit"             },             "url" : "https: //jenkins_url/job/test/job/pavlo-testing2/7/display/redirect" ,             "repository" : {                 "type" : "repository" ,                 "full_name" : "owner/repo" ,                 "links" : {                     "self" : {                         "href" : "https: //api.bitbucket.org/2.0/repositories/owner/repo"                     },                     "html" : {                         "href" : "https: //bitbucket.org/owner/repo"                     },                     "avatar" : {                         "href" : "https: //bytebucket.org/ravatar/%7Bc62b3a64-3697-40a5-94ec-2796afa25000%7D?ts= default "                     }                 },                 "name" : "Repo:name" ,                 "uuid" : "{c62b3a64-3697-40a5-94ec-2796afa25000}"             },             "description" : "This commit looks good." ,             "created_on" : "2024-12-13T23:29:47.053768+00:00" ,             "updated_on" : "2024-12-13T23:39:56.610263+00:00" ,             "links" : {                 "self" : {                     "href" : "https: //api.bitbucket.org/2.0/repositories/owner/repo/commit/commit-hash/statuses/build/ddf9e9aceced1716fe9589128812e304"                 },                 "commit" : {                     "href" : "https: //api.bitbucket.org/2.0/repositories/owner/repo/commit/commit-hash"                 }             }         },         {             "key" : "c386732272563dc5ec49d201a7f99b37" ,             "type" : "build" ,             "state" : "SUCCESSFUL" ,             "name" : "Multibranch-Partners » pavlo-testing2 #3" ,             "refname" : "refs/heads/pavlo-testing2" ,             "commit" : {                 "hash" : "commit-hash" ,                 "links" : {                     "self" : {                         "href" : "https: //api.bitbucket.org/2.0/repositories/owner/repo/commit/commit-hash"                     },                     "html" : {                         "href" : "https: //bitbucket.org/owner/repo/commits/commit-hash"                     }                 },                 "type" : "commit"             },             "url" : "https: //jenkins_url/job/Multibranch-Partners/job/pavlo-testing2/3/display/redirect" ,             "repository" : {                 "type" : "repository" ,                 "full_name" : "owner/repo" ,                 "links" : {                     "self" : {                         "href" : "https: //api.bitbucket.org/2.0/repositories/owner/repo"                     },                     "html" : {                         "href" : "https: //bitbucket.org/owner/repo"                     },                     "avatar" : {                         "href" : "https: //bytebucket.org/ravatar/%7Bc62b3a64-3697-40a5-94ec-2796afa25000%7D?ts= default "                     }                 },                 "name" : "Repo:name" ,                 "uuid" : "{c62b3a64-3697-40a5-94ec-2796afa25000}"             },             "description" : "This commit looks good." ,             "created_on" : "2024-12-13T23:29:47.520499+00:00" ,             "updated_on" : "2024-12-19T09:55:09.780075+00:00" ,             "links" : {                 "self" : {                     "href" : "https: //api.bitbucket.org/2.0/repositories/owner/repo/commit/commit-hash/statuses/build/c386732272563dc5ec49d201a7f99b37"                 },                 "commit" : {                     "href" : "https: //api.bitbucket.org/2.0/repositories/owner/repo/commit/commit-hash"                 }             }         }     ],     "pagelen" : 10,     "size" : 2,     "page" : 1 } When I sent the API call to    https://api.bitbucket.org/2.0/repositories/ <owner>/<repo_slug>/pullrequests/<PR-id>  I see the information about the PR.   Do you have any idea what the issue might be?  and thank you for your help I appreciate it. 

          Nikolas Falco added a comment - - edited

          The last commit in your PR does not have any build statuses associated.

          Furthermore the commit you had point in the second call (I suppose it is the last in your PR) have build statuses associated to branch job and not PR job (I see from the 2 different jenkins URL).

          Do you have configured multibranch project to build pull request jobs (trait Discover pull requests from origin) ?

          I think you did not configured (from step 4. Run any build for any branch) and you were trusting that the commits have build statuses associated to a branch job, since the refname was not valued than it was displayed also in the Bitbucket PR page (that was the bug I resolved).

          If you want see a build statuses in the Bitbucket PR page than you must have a specific jenkins job under the PR tab in jenkins

          Something like

          https://jenkins_url/job/owner/job/repo_slug/view/change-requests/job/PR-786/

          but you have this

          https://jenkins_url/job/owner/job/repo_slug/job/branch_name

          Nikolas Falco added a comment - - edited The last commit in your PR does not have any build statuses associated. Furthermore the commit you had point in the second call (I suppose it is the last in your PR) have build statuses associated to branch job and not PR job (I see from the 2 different jenkins URL). Do you have configured multibranch project to build pull request jobs (trait Discover pull requests from origin ) ? I think you did not configured (from step 4. Run any build for any branch) and you were trusting that the commits have build statuses associated to a branch job, since the refname was not valued than it was displayed also in the Bitbucket PR page (that was the bug I resolved). If you want see a build statuses in the Bitbucket PR page than you must have a specific jenkins job under the PR tab in jenkins Something like https://jenkins_url/job/owner/job/repo_slug/view/change-requests/job/PR-786/ but you have this https://jenkins_url/job/owner/job/repo_slug/job/branch_name

          Pavlo added a comment -

          nfalco thank you for your help! You were right, and I’ve managed to fix the issue with the PR status. Thanks again!

          Pavlo added a comment - nfalco thank you for your help! You were right, and I’ve managed to fix the issue with the PR status. Thanks again!

            nfalco Nikolas Falco
            pavlo_stasyshyn Pavlo
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: