Configure Webhook to Jenkins for Bitbucket Cloud
Once Webhook to Jenkins for Bitbucket Cloud has been successfully installed, the next step is configuring the app in Bitbucket Cloud. You can configure Connections and Hook settings at the Workspace or Repository level.
Open Webhook to Jenkins from a workspace
Log in as an Administrator and select the profile avatar in the top-right corner of any Bitbucket page.
Select the applicable workspace from the Recent Workspace list or select All Workspaces and the workspace from the list.
Click Settings next to the profile avatar and select Workspace settings from the Settings options.
When the Workspace settings page opens, scroll to the bottom of the left sidebar and select Webhook to Jenkins for Bitbucket under Webhook to Jenkins for Bitbucket Cloud.
The Webhook to Jenkins for Bitbucket page opens.
A | Connect to Jenkins servers to use in your integration. | |
B | Set your Jenkins instance at the Repository levels, configure options, and test the configuration settings once set. Configure specific events that trigger Jenkins builds and test configuration in each repository’s settings. | |
C | WBJJ | select the WBJJ icon and select:
|
D | Search | Search for specific Jenkins server instances. Type a portion of the Jenkins server address into the search bar. When the server appears in the list, select the Options icon for the server entry and select:
|
E | Opens the Add Jenkins Instance dialog | |
F | Connections list | List of previously created connections. Each entry has:
|
You are currently in Webhook to Jenkins for Bitbucket Cloud documentation.
Configuration
Add a connection
Select Add Jenkins Instance to open the Add Jenkins Instance dialog.
Enter the URL to the Jenkins instance. This is the base URL for your Jenkins instance, not a link to a specific job—for example, https://abc.yourtestingjenkins.net.
Enter the Jenkins Username and Password associated with the Jenkins job you want to connect to. If you are configuring Webhook to Jenkins to use the Direct Job trigger, you must fill in your Jenkins credentials here.
If you are using Git plugin version 4.11.4 or higher, enter the
notifyCommit
access token. See Access Token Requirements for Git plugin for instructions regarding generating and using the token.Click Save.
The server instance now appears in the Jenkins Server list with a new status and Workspace, indicating this is a workspace-level connection, rather than a repository-level.
When you create a Jenkins connection, information and direction regarding the next configuration step opens in the bottom-left corner of the page. Click Hook settings to continue to that tab.
Hook Settings
Set your Jenkins instance hook settings at either the Workspace or Repository level, configure options, and test the configuration settings once they have been set.
Select the Hook Settings tab.
Select a Project and Repository from the dropdown lists to see any instances that exist for that project/repository pair.
Any current hook settings instances in the list display the Status (enabled or disabled), the Project name, and the Repository name.Select Add to move to the New Hook settings configuration page.
Enable Webhook to Jenkins for this configuration.
Select the Project and Repository from the dropdown lists to associate the Bitbucket repository with a Jenkins job.
Select Add Jenkins instance to open the Instance Details dialog. If you select a Project/Repository pair with an existing configuration, the Configuration already exists message appears.
Jenkins URL - Enter the URL to the Jenkins instance. This is the base URL for your Jenkins instance, not a link to a specific job. For example, https://abc.yourtestingjenkins.net.
Jenkins Endpoint Notification Type - Select an endpoint from the following options:
Bitbucket Source plugin - This allows Jenkins to use Bitbucket Server as a source for multi-branch projects. It also provides the required connectors for the Bitbucket Server Project folder (also known as repositories auto-discovering). The Repo Clone URL and Check Poll SCM options are not used with the Bitbucket source Plugin.
Git plugin - Provides fundamental git operations for Jenkins projects. It can poll, fetch, checkout, branch, list, merge, tag, and push repositories.
Direct Job Trigger - This endpoint allows you to emulate clicking the Build Now button on the Jenkins job page for selected jobs. When the hook event is fired, it has the same effect as selecting this button manually for required jobs. Selecting this endpoint opens the Jobs List field. Type the name of the Jenkins job to see the list of matching jobs for this repository and select up to a maximum of five jobs to be triggered by Webhook to Jenkins. See Configure with Direct Job Triggers for more information.
To determine which plugin your Jenkins instance currently uses, log into your Jenkins instance, and from the Dashboard, select Manage Jenkins. Under System Configuration, select Manage Plugin and look for either the Git or Bitbucket Branch Source plugin. If neither plugin is shown, visit the Bitbucket Branch Source or Git plugin pages for information and download location, and consult your system administrator. If both plugins are present, examine the jobs you want to trigger and select the plugin that best matches your requirements.
Freestyle project - use the Git plugin
Configuration - If the job has the Poll SCM checkbox, use the Git plugin
Configuration - If the job has the Branch Sources section, use the Bitbucket Branch Source plugin
See the What plugin should I use page for more information regarding the type of Job you can use with each plugin.
Repo Clone URL - URL that Jenkins uses to clone the repo. Select HTTP or SSH protocol, and Webhook to Jenkins populates the URL field automatically in that format, or select Custom and manually enter the URL.
HTTP - Configure Jenkins to use HTTP to clone the repo.
SSH - Configure Jenkins to use SSH to clone the repo.
Custom - Manually enter the URL for the Jenkins instance.
Bitbucket defaults to suggesting a clone URL with the HTTP protocol if you haven’t set up a public SSH key in your settings.
Check Poll SCM - The Check Poll SCM notification appears in the Instance Details box. Select Go To Jenkins to access the Source Code Management section and make sure the Check Poll SCM option is selected. See Configure Jenkins - Webhook to Jenkins for Bitbucket Cloud for instructions.
Select Save when finished.
You can also add additional Jenkins instances. Select another project/repository pair and select Add Jenkins instance to repeat the process.
Settings
Project/Repository - The Project and Repository selected on the Hook Settings tab are carried through to the Settings tab.
Advanced
Committers to Ignore - Select or enter the names of Bitbucket committers or access keys whose pushes/merges should not trigger a Jenkins notification.
Branch/tag Options - Control the branches and tags allowed to be built from.
Select a branch option from the dropdown. Separate items with a space and use * for a wildcard at the end of each item.
Option | Description |
---|---|
Build all | This is the default selection. All branches trigger builds. |
Build from | List of Branches that can trigger a build. |
Ignore from | List of Branches that cannot trigger a build. |
Build RegExp | Any Branches that match the value entered can trigger a build. |
Ignore RegExp | Any Branches that match the value entered cannot trigger a build. |
Limit events - Select each event you want to trigger Jenkins. All events are selected by default except the Pull Request Approved option.
Event | Description |
---|---|
Pull Request Opened | Triggers whenever a pull request is opened. |
Pull Request Approved | Triggers each time a reviewer approves a pull request. |
Pull Request Merged | Triggers after a pull request is merged. |
Open Pull Request Refs Changed | Triggers when a change occurs to any git reference, a base branch of at least one active Pull Request. This includes commits, pushes, edits, branch creations, and more. |
Non-Pull Request Refs Changed | Similar to Open Pull Request Refs, but triggers for changes in references that do not participate in any active Pull Request. |
Trigger job poll if the branch is deleted - When a branch is merged or deleted in Bitbucket, select this option for Jenkins to remove the branch from its pipeline.
Job Parameters
The Job Parameters option sends custom URL parameters to Jenkins during the notification/trigger process. To use this option, you must also configure Jenkins to accept URL parameters. Refer to Send URL parameters to Jenkins for more information.
Under the Job parameters heading, enter the Parameter name. This is the same name used when configuring the parameter name in Jenkins.
Select a predefined parameter or type in a parameter value in the Parameter name field. You can also create a custom value by entering a string value containing any text that is not the same as a predefined parameter. This parameter must also be defined in Jenkins. See Send URL parameters to Jenkins for more information.
Click Add.
The name and value are added to the Job parameters list. Any custom value has a CUSTOM label attached when it appears in the list.
Click the Trash icon to remove the entry from the list.
Available Parameters
To pull information from Bitbucket to use as a parameter (like the branch name), refer to the table below.
For example, TARGET_BRANCH
PR_DESTINATION
, where PR_DESTINATION
is the branch name of the destination branch.
Parameter | Description |
---|---|
PR_DESTINATION | The branch name of the destination branch (Only available in pull requests). |
PR_SOURCE | The branch name of the source branch (Only available in pull requests). |
PR_SOURCE_COMMIT | The most recent commit id/reference for the source branch (Only available in pull requests). |
PR_DESTINATION_COMMIT | The most recent commit id/reference for the destination branch (Only available in pull requests). |
PR_ID | The pull request ID number (Only available in pull requests). |
PR_URL | The URL of the pull request (Only available in pull requests). |
PR_TITLE | The title of the pull request (Only available in pull requests). |
PR_ACTION | The action that triggered build for the pull request (Only available in pull requests). |
PR_REVIEWERS | The pull request reviewer display names (Only available in pull requests). |
PR_REVIEWERS_SLUG | The pull request reviewer slugs (Only available in pull requests). |
REPOSITORY | The repository being affected by the event. |
PROJECT | The project the repository being affected by the event is located in. |
BRANCH | The branch associated with the event. |
COMMIT | The commit id/reference associated with the event. |
USER | The username of the user who initiated the event. |
When you have finished with the configuration, click Test to confirm your settings are valid. You’ll receive a Connection Succeeded message if your settings are valid, or a message providing details as to what settings requires investigation.
Click Save when finished.
General
Skip SSL Validation - Self-signed certificates sometimes cause the client (Bitbucket) to deny the trigger build request. When selected, this option allows all certificates to be accepted, including self-signed certificates. We recommend only using the Skip SSL Validation option in select situations, such as in a test environment that uses self-signed certificates.
Omit Builds page - This option removes the Webhook to Jenkins Builds menu item from the Repository side menu.
Open Webhook to Jenkins from a repository
You can also configure Webhook to Jenkins at the repository level.
Click the Repositories tab and select a repository. When the left sidebar menu opens, select Repository settings .
When the Repository details page opens, scroll to the bottom of the left sidebar and select Configure Webhook to Jenkins under Webhook to Jenkins for Bitbucket Cloud.
The Webhook to Jenkins for Bitbucket page opens.
A | Connect to Jenkins servers to use in your integration. | |
B | Set your Jenkins instance at the Repository levels, configure options, and test the configuration settings once set. Configure specific events that trigger Jenkins builds and test configuration in each repository’s settings. | |
C | WBJJ | select the WBJJ icon and select:
|
D | Search | Search for specific Jenkins server instances. Type a portion of the Jenkins server address into the search bar. When the server appears in the list, select the Options icon for the server entry and select:
|
E | Opens the Add Jenkins Instance dialog | |
F | Connections list | List of previously created connections. Each entry has:
|
Add a Connection
Creating a connection to Jenkins at the repository level is similar to creating one at the workspace level. There are, however several differences in their behavior:
connections added at a repository level are only visible at the workspace level or for that specific repository.
you can create and edit connections according to the permissions you have. Workspace administrators can manage any connections, and repository admins can only manage the connections that belong to the repos to which they have access.
when added to the Connections list, repo-level connections have a different scope and indicate the project and repository
Connections created at the workspace level cannot be edited or deleted at the repository level.
Create a connection at the repository level
Click New Connection. The New Jenkins Connection page opens.
Enter the Jenkins URL. This is the base URL for your Jenkins instance, not a link to a specific job—for example, https://abc.yourtestingjenkins.net.
If you are using Git plugin version 4.11.4 or higher, enter the
notifyCommit
access token. See the Access Token Requirements for Git plugin - Webhook to Jenkins for Bitbucket Cloud article for instructions regarding generating and using the token.Enter the Jenkins Username and Password associated with the Jenkins job you want to connect to. If you are configuring Webhook to Jenkins to use the Direct Job trigger, you must fill in your Jenkins credentials here.
Click Save.
The server instance now appears in the Jenkins Server list with a new status attached. Connections at the repository level also have a Repository as the Scope to indicate this connection is for a repository rather than the workspace. The Project and Repository names associated with the connection are also shown.
Follow the same procedures in the Hook Settings and Settings sections for your repository level configuration.