Integration of BitBucket and SonarQube on Pull Requests

What is the best way to trigger a SonarQube scan/analysis on a Pull Request, upon Pull Request creation in BitBucket?

Tech Stack:

BitBucket server v4.14.5 hosted on prem

SonarQube server 6.6 hosted on prem

Jenkins has been used to run the scans previously; would be easiest to continue down that path.

Mibex plugin not an option as it creates a new project and that workflow isn’t acceptable to my architect.

Ideally, workflow would be:

Pull Request Workflow:

Developer creates pull request - pull request triggers SonarQube scan - scan posts results back to BitBucket.

Merge to Master Workflow:

On pull request merge to ‘master’ branch, another SonarQube scan is run against “master” to maintain baseline quality of code for ‘master’

So… I solved this… I think it should be documented, how this is done… I’ve seen a bunch of stuff online, most of it doesn’t work. I’ll post my working implementation somewhere and share it on the community site. This was a bit of a pain.