After upgrading to Bitbucket Server 7.0.1, we get this kind of error for every pull request in multibranch projects in which Jenkins has been configured to build the result of merging the pull request:
{noformat} ERROR: Could not do lightweight checkout, falling back to heavyweight java.io.FileNotFoundException: URL: /rest/api/1.0/projects/SISUREDACTED/repos/rahti-hybridredacted/browse/Jenkinsfile?at=pull-requests%2F771%2Fmerge&start=0&limit=500 at com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.getRequest(BitbucketServerAPIClient.java:831) at com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.getFileContent(BitbucketServerAPIClient.java:1123) at com.cloudbees.jenkins.plugins.bitbucket.filesystem.BitbucketSCMFile.content(BitbucketSCMFile.java:98) at jenkins.scm.api.SCMFile.contentAsString(SCMFile.java:335) at org.jenkinsci.plugins.workflow.multibranch.SCMBinder.create(SCMBinder.java:107) at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:303) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:427) {noformat}
Jenkins then does the heavyweight checkout and successfully merges the pull request, so the project ultimately builds OK, but the heavyweight checkout consumes a lot of time and disk space.
I don't know whether there is any simple way to fix this in the bitbucket-branch-source plugin. If Bitbucket Server has deliberately ceased publishing "refs/pull-requests/*/merge", perhaps the plugin could do a three-way merge on Jenkinsfile only, rather than on the entire tree. That would require a REST API for getting the commit ID of a merge base though, and I don't know whether such a thing exists.
After upgrading to Bitbucket Server 7.0.1, we get this kind of error for every pull request in multibranch projects in which Jenkins has been configured to build the result of merging the pull request:
{noformat} ERROR: Could not do lightweight checkout, falling back to heavyweight
at com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.getRequest(BitbucketServerAPIClient.java:831) at com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.getFileContent(BitbucketServerAPIClient.java:1123) at com.cloudbees.jenkins.plugins.bitbucket.filesystem.BitbucketSCMFile.content(BitbucketSCMFile.java:98) at jenkins.scm.api.SCMFile.contentAsString(SCMFile.java:335) at org.jenkinsci.plugins.workflow.multibranch.SCMBinder.create(SCMBinder.java:107) at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:303) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:427) {noformat}
Jenkins then does the heavyweight checkout and successfully merges the pull request, so the project ultimately builds OK, but the heavyweight checkout consumes a lot of time and disk space.
I don't know whether there isThere might not be any simple way to fix improve this in the bitbucket-branch-source plugin. If Bitbucket Server has deliberately ceased publishing "refs/pull-requests/*/merge", perhaps the plugin could do a three-way merge on Jenkinsfile only, rather than on the entire tree. That would require
- One way might be to use the REST API to get Jenkinsfile from the target branch ([/rest/api/1.0/projects/\{projectKey\}/repos/\{repositorySlug\}/browse/\{path:.*\}|https://docs.atlassian.com/bitbucket-server/rest/7.0.1/bitbucket-rest.html#idp208]) and any Jenkinsfile changes of the pull request as a patch ([/rest/api/1.0/projects/\{projectKey\}/repos/\{repositorySlug\}/pull-requests/\{pullRequestId\}.patch|https://docs.atlassian.com/bitbucket-server/rest/7.0.1/bitbucket-rest.html#idp289] gives the standard diff format but does not support limiting to a single file; [/rest/api/1.0/projects/\{projectKey}/repos/\{repositorySlug}/pull-requests/\{pullRequestId}/diff/\{path:.*}|https://docs.atlassian.com/bitbucket-server/rest/7.0.1/bitbucket-rest.html#idp229] supports that but the output is JSON) and then apply the patch to Jenkinsfile at the Jenkins master. - Alternatively, if Bitbucket Server has a REST API for getting querying the commit ID of a merge base though of a pull request, then the plugin could first use that, then get Jenkinsfile from the three commits, and I don't know whether finally do the three-way merge. However, there does not seem to be such a thing exists an API.
After upgrading to Bitbucket Server 7.0.1, we get this kind of error for every pull request in multibranch projects in which Jenkins has been configured to build the result of merging the pull request:
{noformat} ERROR: Could not do lightweight checkout, falling back to heavyweight java.io.FileNotFoundException: URL: /rest/api/1.0/projects/REDACTED/repos/redacted/browse/Jenkinsfile?at=pull-requests%2F771%2Fmerge&start=0&limit=500 at com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.getRequest(BitbucketServerAPIClient.java:831) at com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.getFileContent(BitbucketServerAPIClient.java:1123) at com.cloudbees.jenkins.plugins.bitbucket.filesystem.BitbucketSCMFile.content(BitbucketSCMFile.java:98) at jenkins.scm.api.SCMFile.contentAsString(SCMFile.java:335) at org.jenkinsci.plugins.workflow.multibranch.SCMBinder.create(SCMBinder.java:107) at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:303) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:427) {noformat}
Jenkins then does the heavyweight checkout and successfully merges the pull request, so the project ultimately builds OK, but the heavyweight checkout consumes a lot of time and disk space.
There might not be any simple way to improve this in the bitbucket-branch-source plugin. If Bitbucket Server has deliberately ceased publishing "refs/pull-requests/*/merge", perhaps the plugin could do a three-way merge on Jenkinsfile only, rather than on the entire tree.
- One way might be to use the REST API to get Jenkinsfile from the target branch ([/rest/api/1.0/projects/\{projectKey\}/repos/\{repositorySlug\}/browse/\{path:.*\}|https://docs.atlassian.com/bitbucket-server/rest/7.0.1/bitbucket-rest.html#idp208]) and any Jenkinsfile changes of the pull request as a patch (, and then apply the patch to Jenkinsfile at the Jenkins master. Unfortunately, it does not seem easy to get a patch that can be applied: **[/rest/api/1.0/projects/\{projectKey\}/repos/\{repositorySlug\}/pull-requests/\{pullRequestId\}.patch|https://docs.atlassian.com/bitbucket-server/rest/7.0.1/bitbucket-rest.html#idp289] gives the standard diff format but does not support limiting to a single file;. ** [/rest/api/1.0/projects/\{projectKey}/repos/\{repositorySlug}/pull-requests/\{pullRequestId}/diff/\{path:.*}|https://docs.atlassian.com/bitbucket-server/rest/7.0.1/bitbucket-rest.html#idp229] supports that limiting to a single file, but the output is JSON) and then apply the patch would thus be more difficult to Jenkinsfile at the Jenkins master apply. - Alternatively, if Bitbucket Server has a REST API for querying the commit ID of a merge base of a pull request, then the plugin could first use that, then get Jenkinsfile from the three commits, and finally do the three-way merge. However, there does not seem to be such an API.
It seems that unless non-author user actually tries to view the PR, the "/from" ref is not created. So when I just use PRs on my own - "/from" is not created whatsoever, that's seems to be a severe case
I can think of two approaches that do not rely on Bitbucket Server updating the "/refs/pull-requests/{id}/from" ref:
Take the commit ID from the webhook event payload. In BSERV-8268, Atlassian enabled uploadpack.allowReachableSHA1InWant, so this should work even if that commit is no longer the tip of any branch, as long as it is still reachable. However, if a user of Jenkins manually triggers a build, then I guess the webhook payload will not be available.
I can think of two approaches that do not rely on Bitbucket Server updating the "/refs/pull-requests/\{id\}/from" ref: * Take the commit ID from the [webhook event payload|https://confluence.atlassian.com/bitbucketserver070/event-payload-996644369.html]. In [BSERV-8268|https://jira.atlassian.com/browse/BSERV-8268], Atlassian enabled {{uploadpack.allowReachableSHA1InWant}}, so this should work even if that commit is no longer the tip of any branch, as long as it is still reachable. However, if a user of Jenkins manually triggers a build, then I guess the webhook payload will not be available. * Query [/rest/api/1.0/projects/\{projectKey\}/repos/\{repositorySlug\}/pull-requests/\{pullRequestId\}|https://docs.atlassian.com/bitbucket-server/rest/7.0.1/bitbucket-rest.html#idp283] and get the name of the source branch from within the "fromRef" property.
It looks like that is what the Bitbucket Branch Source plugin does anyway, for Bitbucket Cloud. So, fixing the "refs/pull-requests/{id}/from" problem for pull requests within the same repository in Bitbucket Server could be just a matter of removing a few instanceof BitbucketCloudApiClient checks in BitbucketGitSCMBuilder.java and BitbucketSCMFileSystem.java. Fixing it for pull requests between forks would need more changes.
Does Bitbucket Server ensure that the "refs/pull-requests/{id}/from" ref appears (or is updated) immediately after the diff request, or can there be a delay sometimes?
I'm checking manually, so no way to track the time between that. I've created a pull request, did ls-remove, made API call using Postman and re-did ls-remote to verify it appeared
BSERV-12284 "Creating pull request does not reflect the stash-refs/pull-requests/<#> immediately" was moved to SHORT TERM BACKLOG on 2020-04-07. I wonder what Atlassian intends to do.
[BSERV-12284|https://jira.atlassian.com/browse/BSERV-12284] "Creating pull request does not reflect the stash-refs/pull-requests/<#> immediately" was moved to SHORT TERM BACKLOG on 2020-04-07. I wonder what Atlassian intends to do.
It was then moved down to GATHERING INTEREST on 2020-04-14, and the priority was removed. :(