---
title: "Trigger Jenkins to only build pull requests"
canonical: "https://support.appfire.com/space/JENK/150897205/Trigger%20Jenkins%20to%20only%20build%20pull%20requests"
format: markdown
---
> Macro (aura-html)

 When a pull request is created in Bitbucket, Webhook to Jenkins sends pull request references(`**/from`) as well as the branch name. If the pull request is from a fork, the app only sends the pull request reference. This allows users to set up the plugin to only build from pull requests. 

> ℹ️ **These instructions are for the Jenkins Git Plugin 4.0 and higher**. For older versions of the Git Plugin, go [here](https://appfire.atlassian.net/wiki/spaces/JENK/pages/150897290).

> 📝 The cross-repository pull requests with fork repositories are only supported with the Bitbucket Branch Source endpoint.

### Configure Bitbucket Server

To configure Jenkins to only build pull requests::

1. From your Bitbucket repository, click the **Repository Settings** icon > **Hooks** and select **Enabled** or edit the previously enabled Webhook to Jenkins configuration.
2. From the **Advanced Configuration** tab,  select **Build All** from the **Branch Options** dropdown. This skips the allowlist and blocklist checks so that all new commits and tags send the required Jenkins notification.

> ⚠️ The Omit SHA1 Hash Code option must be unchecked in this configuration since it triggers polling mode on the Jenkins side. In this mode, Jenkins processes `refs/heads/*` only. Click the **General Settings tab **and confirm the **Omit SHA1 Hash Code** option is not selected.

![image](media://701e5bf3-bc96-4101-acc4-e6f7ac3c9322)

### Set up a Jenkins Job for Pull Requests

In the job, set the branch specifier to `**/from`. This configures the job so that it only responds to new pull requests.

![image](media://e6a53128-240f-4fd1-8f52-4e0ebcf7f56e)

### Configure Pipeline Job for Pull Requests

When Jenkins to Webhook receives notification it needs to map repository URL and branches to a particular job. Pipeline job implementation uses information from previous builds.

This information includes:

- repository URL
- branch specifier

Configuring the pipeline job can be challenging. The build needs to be started from the Jenkins side:

- when the job is initially configured
- whenever the job is reconfigured (for example, the repository URL or branch specifier is changed)

When only ****/from **branch spec is used, then build can't be started properly. Because **/from branches are not fetched. To solve this issue second branch spec can be added (like for example ***/master** ) and when job is successfully invoked then it can be removed.

> ℹ️ **Triggering the initial build**
> ℹ️ 
> ℹ️ A good way to trigger build after branch spec change is using **Test Configuration**  from any of the **Webhook to Jenkins for Bitbucket Server** tabs. In this case no branch filtering occurs and Jenkins uses exact commit id for checkout.