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

NullPointerException when scan bitbucket mulit-branch

    Details

    • Similar Issues:

      Description

      This will happen when there are some PRs that don't have any commits.

        Attachments

          Issue Links

            Activity

            Hide
            michelzanini Michel Zanini added a comment -

            This bug is a duplication of https://issues.jenkins-ci.org/browse/JENKINS-56309.
            I am also experiencing this and will report steps on how to reproduce.

            Show
            michelzanini Michel Zanini added a comment - This bug is a duplication of https://issues.jenkins-ci.org/browse/JENKINS-56309 . I am also experiencing this and will report steps on how to reproduce.
            Hide
            michelzanini Michel Zanini added a comment -

            To reproduce the issue above, on Bitbucket Cloud, follow the steps:

            • Create a new branch, here we will create a branch called develop.
            • No need to do any commits to it, create another branch from develop, we can call it my_changes
            • Commit something to my_changes
            • Create a PR from my_changes to ** develop**
            • Go to Jenkins and see that there are builds for both branches and the PR
            • Now open Bitbucket Cloud and delete the develop - don't decline the PR (leave it open)
            • Now when opening the PR there will be zero commits on the PR (the target branch no longer exists)
            • Go back to Jenkins multi-branch pipeline and press Scan Multibranch Pipeline Log
            • **When the plugin is canning the PRs it will fail with the exception reported here

            The cause:

            The API call done to get all pull requests is made from:

             

            BitbucketCloudApiClient.getPullRequests()
            

            In the this call, the JSON is parsed to:

             

             

            -> BitbucketPullRequests
               -> List<BitbucketPullRequestValue> values;
                    -> BitbucketPullRequestValueDestination destination;

            And BitbucketPullRequestValueDestination class has this constructor: 

             

             

            @JsonCreator
            public BitbucketPullRequestValueDestination(@NonNull @JsonProperty("repository") BitbucketCloudRepository repository,
                                                        @NonNull @JsonProperty("branch") BitbucketCloudBranch branch,
                                                        @NonNull @JsonProperty("commit") BitbucketCloudCommit commit) {
                this.repository = repository;
                this.branch = branch;
                this.commit = commit;
            
                // redound available the informations into impl objects
                this.branch.setRawNode(commit.getHash());
            }
            

            You can see here:

             

             

            @NonNull @JsonProperty("commit") BitbucketCloudCommit commit
            

            The @NotNull here is what is causing the exception. The JSON is returning null for commit. See:

             

             

            ...
                        "destination": {
                            "commit": null,
                            "repository": {
                                "links": {
                                    ...
                                },
                                "type": "repository",
                                "name": "my-demo-project",
                                "full_name": "my/my-demo-project",
                                "uuid": "{asdsdsd-5b91-44e5-9f76-af5612323123}"
                            },
                            "branch": {
                                "name": "develop"
                            }
                        },
            ...

            I could create a PR to make BitbucketCloudCommit commit nullable.

            But, this field is used in 5 different places, a few of them with a null check.

            It is more work then just making it nullable, I think we might want to filter out PRs with no destination commit and remove then from Jenkins multi-branch jobs...

            Joseph Petersen - if you could fix this it would be great.

             

            -> Workaround is to manually decline the PR on Bitbucket.

             

             

            Show
            michelzanini Michel Zanini added a comment - To reproduce the issue above, on Bitbucket Cloud, follow the steps: Create a new branch, here we will create a branch called develop . No need to do any commits to it, create another branch from develop, we can call it my_changes Commit something to  my_changes Create a PR from  my_changes to **  develop ** Go to Jenkins and see that there are builds for both branches and the PR Now open Bitbucket Cloud and delete the  develop  - don't decline the PR (leave it open) Now when opening the PR there will be zero commits on the PR (the target branch no longer exists) Go back to Jenkins multi-branch pipeline and press  Scan Multibranch Pipeline Log **When the plugin is canning the PRs it will fail with the exception reported here The cause: The API call done to get all pull requests is made from:   BitbucketCloudApiClient.getPullRequests() In the this call, the JSON is parsed to:     -> BitbucketPullRequests -> List<BitbucketPullRequestValue> values; -> BitbucketPullRequestValueDestination destination; And BitbucketPullRequestValueDestination class has this constructor:      @JsonCreator public BitbucketPullRequestValueDestination(@NonNull @JsonProperty( "repository" ) BitbucketCloudRepository repository, @NonNull @JsonProperty( "branch" ) BitbucketCloudBranch branch, @NonNull @JsonProperty( "commit" ) BitbucketCloudCommit commit) { this .repository = repository; this .branch = branch; this .commit = commit; // redound available the informations into impl objects this .branch.setRawNode(commit.getHash()); } You can see here:     @NonNull @JsonProperty( "commit" ) BitbucketCloudCommit commit The @NotNull  here is what is causing the exception. The JSON is returning null for commit. See:     ... "destination" : { "commit" : null , "repository" : { "links" : { ... }, "type" : "repository" , "name" : "my-demo-project" , "full_name" : "my/my-demo-project" , "uuid" : "{asdsdsd-5b91-44e5-9f76-af5612323123}" }, "branch" : { "name" : "develop" } }, ... I could create a PR to make  BitbucketCloudCommit commit nullable. But, this field is used in 5 different places, a few of them with a null check. It is more work then just making it nullable , I think we might want to filter out PRs with no destination commit and remove then from Jenkins multi-branch jobs... Joseph Petersen - if you could fix this it would be great.   -> Workaround is to manually decline the PR on Bitbucket.    

              People

              • Assignee:
                surenpi Rick
                Reporter:
                surenpi Rick
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: