GitHub Branch Source Plugin --> only scan for Pull Requests

Viewed 4030

We use the GitHub Branch Source Plugin in Jenkins. It works great. However it scans both for branches and pull requests.

We want to configure the plugin in such way that it only scans for pull requests. Is this possible? If not, where can we post our feature request?

2 Answers

You can configure this in the job via the checkout behaviors. Just delete the Discover Branches item and it should not find any branches. enter image description here

Using JCaSC / DSL syntax it can be configured using gitHubBranchDiscovery trait with strategyId(1):

              branchSource {
                  source {
                      github {
                          id('ci') // IMPORTANT: use a constant and unique identifier
                          repositoryUrl('https://github.com/OWNER/REPO')
                          repository('REPO')
                          repoOwner('OWNER')
                          apiUri('https://github.com/api/v3')
                          configuredByUrl(false)
                          credentialsId('github-token')
                          traits {
                              gitHubBranchDiscovery {
                                  // 1 = Exclude branches that are also filed as PRs
                                  // 2 = Only branches that are also filed as PRs
                                  // 3 = All branches
                                  strategyId(1)
                              }
                              gitHubPullRequestDiscovery {
                                  // 1 = only PR merge
                                  // 2 = only PR head
                                  // 3 = both PR head and PR merge
                                  strategyId(3) // 3 = both PR head and PR merge from origin
                              }
                          }
                      }
                  }
              }
Related