jenkinsci / templating-engine-plugin

create tool-agnostic, templated pipelines to be shared by multiple teams
https://jenkinsci.github.io/templating-engine-plugin/latest/
Apache License 2.0
171 stars 58 forks source link

Add support for BitBucket Pull Requests #319

Open rayvincent2 opened 1 year ago

rayvincent2 commented 1 year ago

PR Details

Add support for Bitbucket Pull Requests

Description

In order to properly retrieve Jenkins pipeline and template files in a repository, we must perform special detection and handling of BitBucket PRs. Since the SCMHead retrieved from a PR Jenkins branch doesn't have the correct information to create an SCMFileSystem, we must detect if the SCMHead is of type com.cloudbees.jenkins.plugins.bitbucket.PullRequestSCMHead and then create a custom SCMHead of type com.cloudbees.jenkins.plugins.bitbucket.BranchSCMHead which points to the HEAD of the PRs source branch. This allows us to create a SCMFileSystem that will allow us to retrieve the Jenkins pipeline_config.groovy and Jenkinsfile.

This PR fixes #308.

How Has This Been Tested

JTE was inoperable against BitBucket Server 7. After manually building the .hpi from this commit, we installed it and were able to confirm it working without issue.

Testing Environment:

Types of Changes

Checklist

steven-terrana-bah commented 1 year ago

thank you! I'll review as soon as i'm able.

rayvincent2 commented 1 year ago

The flaw that this PR has is that it only generates the SCMFileSystem from the PR's source branch and doesn't perform any kind of merge. It suits our needs as we always rebase all our PRs against the target branch. But I can see this may not be a solution that suits all cases. It may still need a little work.

steven-terrana commented 1 year ago

Thanks @rayvincent2 - another issue is that this now places a required dependency on the Bitbucket Branch Source plugin.

It would be preferable to use the patterns described in the linked documentation to make this an Optional Dependency

rayvincent2 commented 1 year ago

Very good! Thanks for catching that and handing me the perfect resource to take it the extra step. Now I just need to carve out time to make that tweak. I'm a bit busy now, but will get around to it.

Koziol-ku commented 2 months ago

Is it possible to merge this PR?