jenkinsci / bitbucket-branch-source-plugin

Bitbucket Branch Source Plugin
https://plugins.jenkins.io/cloudbees-bitbucket-branch-source
MIT License
215 stars 351 forks source link

PRs from forks won't be detected #521

Open krulls opened 2 years ago

krulls commented 2 years ago

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)

Reproduction steps

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.

lifeofguenter commented 2 years ago

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

krulls commented 2 years ago

@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.

lifeofguenter commented 2 years ago

@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?

krulls commented 2 years ago

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 commented 2 years ago

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.

tanon-adm commented 2 years ago

@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?

sjjarvi commented 2 years ago

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

tanon-adm commented 2 years ago

@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 commented 2 years ago

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

lifeofguenter commented 2 years ago

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

tanon-adm commented 2 years ago

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

lifeofguenter commented 2 years ago

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

tanon-adm commented 2 years ago

@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

lifeofguenter commented 2 years ago

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?

tanon-adm commented 2 years ago

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

Atlassian Bitbucket v7.6.12

lifeofguenter commented 2 years ago

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

krulls commented 2 years ago

@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?

tanon-adm commented 2 years ago

@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.