Skip to content

Fix JENKINS-40465#48

Closed
zigarn wants to merge 1 commit intojenkinsci:masterfrom
zigarn:fix-JENKINS-40465
Closed

Fix JENKINS-40465#48
zigarn wants to merge 1 commit intojenkinsci:masterfrom
zigarn:fix-JENKINS-40465

Conversation

@zigarn
Copy link
Member

@zigarn zigarn commented May 19, 2017

JENKINS-40465
For Bitbucket Server, use only destination repository for repository-related actions

@zigarn
Copy link
Member Author

zigarn commented May 19, 2017

It's not really clean to test BitbucketServerAPIClient class, but I don't know what would be the preferred way in the project (add a method in BitbucketApi which is not really API-related?)

@zigarn zigarn changed the title Fix JENKINS-40465 Fix [JENKINS-40465](https://issues.jenkins-ci.org/browse/JENKINS-40465) May 19, 2017
@zigarn zigarn changed the title Fix [JENKINS-40465](https://issues.jenkins-ci.org/browse/JENKINS-40465) Fix JENKINS-40465 May 19, 2017
For Bitbucket Server, use only destination repository for repository-related actions
@i386
Copy link
Contributor

i386 commented Jul 13, 2017

WDYT @amuniz @stephenc ?

@abishek3876
Copy link

I thought this should be superseded by #53 . Didn't test this scenario though.

@stephenc
Copy link
Member

AIUI this issue is resolved by the changes in JENKINS-43507, specifically

if (scmSource.buildBitbucketClient() instanceof BitbucketCloudApiClient) {
// TODO fix once Bitbucket Cloud has a fix for https://bitbucket.org/site/master/issues/5814
String branchName = ((PullRequestSCMHead) head).getBranchName();
withRefSpec("+refs/heads/" + branchName + ":refs/remotes/@{remote}/" + head.getName());
} else {
String pullId = ((PullRequestSCMHead) head).getId();
withRefSpec("+refs/pull-requests/" + pullId + "/from:refs/remotes/@{remote}/" + head.getName());
}
which will be released in 2.2.0

@zigarn
Copy link
Member Author

zigarn commented Jul 13, 2017

Looks like it could.
Will try it ASAP.

@i386
Copy link
Contributor

i386 commented Jul 17, 2017

@zigarn any luck?

@zigarn
Copy link
Member Author

zigarn commented Jul 17, 2017

I can confirm that using the tag cloudbees-bitbucket-branch-source-2.2.0-beta-1, JENKINS-40465 is already solved.

@zigarn zigarn closed this Jul 17, 2017
@zigarn
Copy link
Member Author

zigarn commented Jul 17, 2017

It's nice with all the options for managing PR. Looking forward to see this released!

@zigarn
Copy link
Member Author

zigarn commented Jul 24, 2017

@i386 @stephenc : I was too quick to give my GO...
There is still a problem: the PullRequests still only store the source owner and repository and then try to get revisionId against it (com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource.retrieve(SCMHead, TaskListener)) but doesn't have access to other repositories than target owner and repository in case of a fork.
The only solution I see is to store both origin and target owner and repository info in PullRequestSCMHead. (But this PR is totally outdated)

@stephenc
Copy link
Member

@zigarn, Bitbucket Server does not have this issue as we use the refs/pull-requests/N/head refspec (not without its own issues though, e.g. https://github.com/topicusfinan/bitbucket-webhooks-plugin/pull/51)

Bitbucket Cloud will work for forks in the same account (which according to Bitbucket is the majority case) but will not work for private forks to your own account as there is NO WAY WHATSOEVER to access those forks without setting the permissions when you fork, see https://bitbucket.org/site/master/issues/5814/reify-pull-requests-by-making-them-a-ref and other issues there

@zigarn
Copy link
Member Author

zigarn commented Jul 24, 2017

@stephenc : no problem with the refspec, but in the code I referenced, the list of branches is checked against the source repository which may not be accessible in case of private fork.

@stephenc
Copy link
Member

@zigarn have you looked at the new 2.2.x code?

@stephenc
Copy link
Member

@zigarn keep in mind that we protect against such inaccessible forks during scanning, so the only time you get to the referenced method is after a full scan has discovered, and we have a guard there: https://github.com/jenkinsci/bitbucket-branch-source-plugin/blob/master/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource.java#L722

@zigarn
Copy link
Member Author

zigarn commented Jul 24, 2017

@stephenc: In the code you're refering, originBitbucket is a bitbucketClient built against the currently scanned repository, not the fork, so no problem to resolve the PR hash.
But when building the PR, no more reference to the target repository and the authentication problems arrived.

When testing by launching a mvn hpi:run on branch master

[lun. juil. 24 18:40:03 CEST 2017] Starting branch indexing...
Connecting to http://bitbucket.mycompany.com using user/******
Repository type: Git
Looking up PROJECT/test_jenkins_pr for branches
Checking branch local_pr from PROJECT/test_jenkins_pr
Checking branch master from PROJECT/test_jenkins_pr
      ‘Jenkinsfile’ found
    Met criteria
No changes detected: master (still at 4c553423451313f310236bb6afda201ec93f8641)

  2 branches were processed
Looking up PROJECT/test_jenkins_pr for pull requests
Checking PR-1 from PROJECT/test_jenkins_pr and branch local_pr
      ‘Jenkinsfile’ found
    Met criteria
No changes detected: PR-1 (still at f7eb292cc308ffb31145ad30c4e0e5ed7c946d51)
Checking PR-2 from ~zigarn/test_jenkins_pr and branch remote_pr
      ‘Jenkinsfile’ found
    Met criteria
No changes detected: PR-2 (still at 2175b660d8055ea35bdd391eb912f8fa7475efb1)

  2 pull requests were processed
[lun. juil. 24 18:40:23 CEST 2017] Finished branch indexing. Indexing took 19 s
Finished: SUCCESS

But, when building PR-2:

java.io.IOException: I/O error when accessing URL: /rest/api/1.0/projects/~zigarn/repos/test_jenkins_pr/branches?start=0
	at com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.getBranches(BitbucketServerAPIClient.java:378)
	at com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource.retrieve(BitbucketSCMSource.java:769)
	at jenkins.scm.api.SCMSource.fetch(SCMSource.java:564)
	at org.jenkinsci.plugins.workflow.multibranch.SCMBinder.create(SCMBinder.java:79)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:214)
	at hudson.model.ResourceController.execute(ResourceController.java:98)
	at hudson.model.Executor.run(Executor.java:410)
Caused by: com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRequestException: HTTP request error. Status: 401: Unauthorized.
{"errors":[{"context":null,"message":"You are not permitted to access this resource","exceptionName":"com.atlassian.bitbucket.AuthorisationException"}]}
	at com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.getRequest(BitbucketServerAPIClient.java:516)
	at com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.getBranches(BitbucketServerAPIClient.java:363)
	... 6 more
Finished: FAILURE

@stephenc
Copy link
Member

@zigarn can you create a JIRA for this new issue

@zigarn
Copy link
Member Author

zigarn commented Jul 25, 2017

JENKINS-45775.
I'm trying some solutions and may come with a PR before the end of the week.

@zigarn zigarn deleted the fix-JENKINS-40465 branch July 26, 2017 09:06
fengxx pushed a commit to fengxx/bitbucket-branch-source-plugin that referenced this pull request Mar 13, 2018
[JENKINS-37219] Add a job property for overriding branch index triggers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants