Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-71355] Avoid Fetching all branches and Tags to retrieve SCM … #708

Merged
merged 5 commits into from
May 30, 2023

Conversation

Dohbedoh
Copy link
Contributor

@Dohbedoh Dohbedoh commented May 29, 2023

…Head

See JENKINS-71355. When retrieving a single SCM Head, BitbucketBranchSource currently fetches all branches (and also tags in the case of a Tag) although it is not necessary.

Note: One challenge / limitation is with Bitbucket Server API that does not have an endpoint to get a single branch information. We can however send a filterText parameter to get what we want and then use a predicate to make sure we have the correct branch (because per my understanding the filter may returns several matches if for example a branch name is a substring of another one). But in most cases, just the branch we look for will be returned.

Your checklist for this pull request

  • Make sure you are requesting to pull a topic/feature/bugfix branch (right side) and not your master branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or in Jenkins JIRA
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Did you provide a test-case? That demonstrates feature works or fixes the issue.

@Dohbedoh
Copy link
Contributor Author

I have run tests against Bitbucket Server branches, tags and PR from origin.
I have not run tests against Bitbucket Cloud yet or PR from forks.

@Dohbedoh
Copy link
Contributor Author

Failing in Bitbucket Cloud because the /2.0/repositories/{owner}/{repo}/pullrequests/{id} returns short commit ID instead of long ones. That eventually causes the AbstractGitSCMSource to fail when using jgit https://github.com/jenkinsci/git-plugin/blob/git-5.0.2/src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java#L1479:

org.eclipse.jgit.errors.InvalidObjectIdException: Invalid id: 620d3c2bc24e
	at org.eclipse.jgit.lib.ObjectId.fromString(ObjectId.java:203)
	at jenkins.plugins.git.AbstractGitSCMSource$SpecificRevisionBuildChooser.<init>(AbstractGitSCMSource.java:1479)
	at jenkins.plugins.git.GitSCMBuilder.build(GitSCMBuilder.java:504)
	at com.cloudbees.jenkins.plugins.bitbucket.BitbucketGitSCMBuilder.build(BitbucketGitSCMBuilder.java:291)
	at com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource.build(BitbucketSCMSource.java:1027)
	at org.jenkinsci.plugins.workflow.multibranch.SCMBinder.create(SCMBinder.java:137)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:312)
	at hudson.model.ResourceController.execute(ResourceController.java:101)
	at hudson.model.Executor.run(Executor.java:442)

Seems like this is a known problem but that in the context the PR commits are never initialized (we never go through the BitbucketCloudBranch#initHeadCommitInfo) method. Called lazily when retrieving information about the PR (getAuthor, getDateMillis, getMessage). We need to force this in this context.

@lifeofguenter
Copy link
Contributor

Thanks @Dohbedoh for this (and also providing tests), I will merge in shortly

@lifeofguenter lifeofguenter added feature java Pull requests that update Java code labels May 30, 2023
@Dohbedoh
Copy link
Contributor Author

@lifeofguenter wait, see my previous comment. I need to adjust this to get the commit IDs from branches in case of Bitbucket Cloud. Will commit shortly.

@Dohbedoh
Copy link
Contributor Author

@lifeofguenter ready for review

@lifeofguenter lifeofguenter merged commit 8b06426 into jenkinsci:master May 30, 2023
14 checks passed
@Dohbedoh Dohbedoh deleted the JENKINS-71355 branch May 31, 2023 00:15
@chwehrli
Copy link

When upgrading this plugin from v803 to v804 multibranch pipeline jobs "don't run" anymore. I can trigger the job but it gets stuck at the very beginning (there's literally no job log) and eventually times out after a couple of minutes. If I kill the job I get the following log:

07:31:45 Started by user Wehrli, Christian 07:32:21 java.lang.InterruptedException 07:32:21 at com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.getResource(BitbucketServerAPIClient.java:917) 07:32:21 at com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.getSingleBranch(BitbucketServerAPIClient.java:639) 07:32:21 at com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.getBranch(BitbucketServerAPIClient.java:590) 07:32:21 at com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.getBranch(BitbucketServerAPIClient.java:130) 07:32:21 at com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource.retrieve(BitbucketSCMSource.java:912) 07:32:21 at jenkins.scm.api.SCMSource.fetch(SCMSource.java:581) 07:32:21 at org.jenkinsci.plugins.workflow.multibranch.SCMBinder.create(SCMBinder.java:99) 07:32:21 at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:312) 07:32:21 at hudson.model.ResourceController.execute(ResourceController.java:101) 07:32:21 at hudson.model.Executor.run(Executor.java:442) 07:32:21 [withMaven] downstreamPipelineTriggerRunListener - Failure to introspect build steps: java.io.IOException: Core Performance ZKB Cluster/master #948 did not yet start 07:32:21 [withMaven] downstreamPipelineTriggerRunListener - Failure to introspect build steps: java.io.IOException: Core Performance ZKB Cluster/master #948 did not yet start 07:32:21 Finished: FAILURE

Jenkins LTS 2.401.1

Any idea what's going on here? Happy to provide additional information or to raise a bug.

@KalleOlaviNiemitalo
Copy link
Contributor

@chwehrli, that seems similar to #721.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature java Pull requests that update Java code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants