bitbucket-branch-source-plugin icon indicating copy to clipboard operation
bitbucket-branch-source-plugin copied to clipboard

PRs from forks won't be detected

Open krulls opened this issue 4 years ago • 18 comments

Version report

Jenkins and plugins versions report: Jenkins LTS 2.303.2 Pipeline Multibranch plugin 2.26 (https://plugins.jenkins.io/workflow-multibranch) Bitbucket Branch Source plugin 2.9.11 and many others...

Bitbucket: DataCenter edition, LTS 7.6.2 Post Webhooks add-on 2.5.3 (https://marketplace.atlassian.com/apps/1215474/post-webhooks-for-bitbucket?tab=overview&hosting=datacenter)

  • What Operating System are you using (both controller, and any agents involved in the problem)? Controller: CentOS 7

Reproduction steps

  • create a new "Multibranch Pipeline" job
  • set up Branch source to the Bitbucket instance (we have DataCenter edition, version 7.6.2)
  • set up the correlated repository (the repo has webhook configured to report changes to the corresponding endpoint on Jenkins side)
  • add behaviours: discover branches, discover PRs from origin, discover PRs from forks, see image
  • once saved, the job detects all branches in the origin repo and creates jobs properly
  • create a fork of the origin repo
  • create a branch in the fork repo
  • create a PR in the origin repo: source is the new branch in the fork

Results

Expected result:

PR is getting detected, new job created and being built

Actual result:

Nothing is happening, the multibranch pipeline job is not aware of the new PR

Workaround

I can manually trigger a scan of the multibranch pipeline job. This reveals the outstanding PR from the fork and creates a job for it.

krulls avatar Nov 19 '21 13:11 krulls

Are the webhooks being created? I would most probably also recommend using the native webhook plugin.

lifeofguenter avatar Nov 19 '21 15:11 lifeofguenter

@lifeofguenter : Not sure what you mean with "created". They are configured the way that we have that logic running for years already. There was no change on Bitbucket side but upgrades on Jenkins side, that's why I assume it is related with this plugin here. And there were suspicious changes which could have introduced a buggy behaviour, see https://github.com/jenkinsci/bitbucket-branch-source-plugin/pull/445.

Thank you for the hint about the native webhooks in Bitbucket. We plan to migrate the configurations later on.

krulls avatar Nov 22 '21 07:11 krulls

@krulls this plugin will create native webhooks if it is given permissions to do so. I can not say if it works or not on custom setups, but on the setup intended it will work.

Can you check in your webhook settings there should be a log in bitbucket of events - so you see any reaching your jenkins?

lifeofguenter avatar Nov 22 '21 07:11 lifeofguenter

Before we go into further detail of the logic and logs of the webhook that is being triggered by Bitbucket actions (commits, PR changes) I want to inform you that we rolled back the plugin to version 2.9.9 and it works as before. That means: In a multibranch pipeline job a new job gets created and built as soon as I open a PR in the origin repository. The source of this PR is a branch in a fork repository.

krulls avatar Nov 22 '21 09:11 krulls

image This is the configuration of the webhook trigger in the Bitbucket repository. You can see that it targets the webhook endpoint of this plugin.

krulls avatar Nov 22 '21 09:11 krulls

@lifeofguenter I faced the same issue. I updated the plugin and after that Jenkins stopped detecting PRs from repository forks. I can downgrade the plugin to version 2.9.8 only, but this version has security issues. Is there any chance that the bug will be fixed?

tanon-adm avatar Jan 28 '22 19:01 tanon-adm

@tanon-adm Is this same the issue as mentioned in https://github.com/jenkinsci/bitbucket-branch-source-plugin/issues/469 ?

sjjarvi avatar Jan 28 '22 20:01 sjjarvi

@sjjarvi No, I didn't get a message like "‘Jenkinsfile’ not found". Everything works as expected on version 2.9.8 and it doesn't work on version 751.vda_24678a_f781 (after creating a PR from fork there are no messages in the log, as if nothing happened). After manually starting the scan, the PR is found and the build is started.

tanon-adm avatar Jan 30 '22 20:01 tanon-adm

@lifeofguenter @sjjarvi Do you have any updates on my request? Maybe you need some additional information from my side?

tanon-adm avatar Feb 02 '22 07:02 tanon-adm

@tanon-adm I am unable to replicate the issue - are you using native webhooks?

lifeofguenter avatar Feb 02 '22 10:02 lifeofguenter

@lifeofguenter No, I'm using 'Plugin' webhook implementation.

tanon-adm avatar Feb 02 '22 19:02 tanon-adm

Do you mind checking if it works better using the native webhook?

lifeofguenter avatar Feb 03 '22 00:02 lifeofguenter

@lifeofguenter I have checked it now, with the native webhook it also doesn't work. Additional information: Jenkins LTS 2.319.2 Pipeline Multibranch plugin 706.vd43c65dec013 (https://plugins.jenkins.io/workflow-multibranch) Bitbucket Branch Source plugin 751.vda_24678a_f781

tanon-adm avatar Feb 03 '22 07:02 tanon-adm

can you please put a screenshot of your complete job-config and also which webhooks are enabled for the project?

Then I can try to replicate. Which version of Bitbucket are you using?

lifeofguenter avatar Feb 03 '22 14:02 lifeofguenter

My job config: изображение изображение изображение изображение

Atlassian Bitbucket v7.6.12

tanon-adm avatar Feb 03 '22 16:02 tanon-adm

Hmm I am having difficulties replicating the issue. I created a new Bitbucket Server repo (v7.19.1), forked it, and the build immediately started in Jenkins (LTS, latest plugins):

Screenshot from 2022-02-03 23-03-27

My settings are slightly different, however I do not see anything obvious that might cause an issue:

Screenshot from 2022-02-03 23-08-28

Screenshot from 2022-02-03 23-08-09

However:

My webhook config looks completely different (was created automatically by Jenkins):

Screenshot from 2022-02-03 23-10-03

And that is the only webhook created - I do not have any separate webhook for PRs.

I am also not sure if there is a difference since I use branch-source/org-folder as opposed to multibranch pipeline

lifeofguenter avatar Feb 03 '22 22:02 lifeofguenter

@lifeofguenter : The difference is that you use the Bitbucket native webhook, but @tanon-adm and me use the Post Webhooks add-on from the marketplace. Then it might just be related to this add-on. I am triggering a test internally to check if your proposed configuration works, then it seems we need to migrate away from the add-on.

(some extra info: the vendor of the add-on raises costs for it from a certain version, that's why we stuck to the rather old version of it. most current version is 3.25.24)

@tanon-adm : can you check which version of the add-on you have installed in your Bitbucket instance?

krulls avatar Feb 04 '22 06:02 krulls

@krulls We use version 1.12.23. It's old, but there is following warning message "You may update this app but the newest version isn't free. You can purchase a license through Atlassian.", so this is most likely the reason why. So you are right.

tanon-adm avatar Feb 04 '22 12:02 tanon-adm