Configure Jenkins - Webhook to Jenkins for Bitbucket Cloud

For Webhook to Jenkins for Bitbucket Cloud to work correctly, you must perform some configuration steps in Jenkins. This section provides these configuration steps.

This section does not include detailed instructions regarding the initial setup of your Jenkins or Bitbucket instances. For more information regarding these topics, refer to Bitbucket Cloud and Jenkins documentation.

Before you begin

Before you begin configuring your Jenkins instance, confirm the following actions have been performed:

Configure Jenkins for use with Webhook to Jenkins for Bitbucket Cloud

The Jenkins configuration steps are different depending on the plugin you use as the Jenkins endpoint in your Webhook to Jenkins for Bitbucket Cloud configuration. Refer to the What plugin should I use page for information regarding each plugin, and follow the Bitbucket Branch Source plugin or Git plugin instructions below, depending on the plugin you use.

Jenkins configuration - Classic UI

Bitbucket Branch Source plugin

  1. Log into your Jenkins instance.

  2. Go to Manage Jenkins > Configure System and scroll down to Bitbucket Endpoints.

  3. Click Add and select Bitbucket Cloud from the dropdown.

  4. Click Save.

Configure Jenkins multibranch pipeline job

These instructions apply to Multibranch Pipeline jobs and Bitbucket Team Jobs. Other Jenkins jobs do not have the Branch Source configuration option available.

A Jenkinsfile is required for multibranch jobs. A Jenkinsfile is defined in your repository and describes how your pipeline will work.

  1. Select a job from the Dashboard page and click Configure.

  2. On the Configuration page, scroll down to the Branch Sources section (for a Bitbucket Project configuration, this section is called Projects).

  3. Click Add Source and select Bitbucket to expand the section.

  4. Enter information in the following fields:
    Server - select the Bitbucket Server endpoint you added in the Bitbucket Branch Source plugin section
    Credentials -select your administrator Bitbucket credentials. If you do not have credentials configured, click Add to open the Jenkins Credentials Provider dialog and click Jenkins. From the the Kind section, click the dropdown to open the list of available options. Select the credential type you want to use, fill in the applicable information and click Add.

    • If you use the Username/Password credentials, be sure to use the Bitbucket App Password. See App Passwords to learn more about setting up an app password in Bitbucket Cloud.

    • While you can use any of the authentication methods that best fits your organization’s security policy, we recommend using SSH Username with private key. Go to Configure SSH Credentials for Webhook to Jenkins for Bitbucket for instructions on how to set up SSH credentials.

Owner - enter your workspace key

Repository Name - select the name of the Bitbucket repository associated with this Jenkins job.

 

 

Git plugin

  1. Log into your Jenkins instance.

  2. Add or select the job you want to associate with your Bitbucket repository. We recommend choosing a Freestyle job that works best with the Git plugin.

  3. Once you are in the job, click Configure from the left menu.

  4. Select the Source Code Management tab and the Git option when the Configuration page opens.

  5. In the Repository URL field, enter the URL for the Bitbucket repository you want Jenkins to integrate with. This is the same URL as the one displayed in the Repo Clone URL field located in the Instance Details for your Jenkins instance of Webhook to Jenkins.

  6. Click Add to open the Jenkins Credentials Provider dialog and click the Kind pull down to open the list of available options. Select the credential type you want to use and click Add. While you can use any of the authentication methods that best fits your organization’s security policy, we recommend using SSH Username with private key. Go to Configure SSH Credentials for Webhook to Jenkins for Bitbucket for instructions on how to set up SSH credentials.

  7. In the Branches to build section, click Add Branch to identify the specific branches you want to track in a repository. Enter the branch in the Branch Specifier field. Leave the field blank for all branches to be examined for changes and build. By default the field is set to */master. Confirm the branch name is entered correctly. Click the Help icon next to the Branch Specifier for more formatting information.

  8. Select the Build Trigger tab.

  9. Select Poll SCM. This is an important step, as the build won’t trigger in Jenkins if this option is not selected.

Jenkins configuration - Blue Ocean

Blue Ocean is a Jenkins front-end that provides users with an improved experience when creating pipeline jobs. For complete information regarding Blue Ocean, refer to their documentation.

To trigger a Jenkins job through Webhook to Jenkins using Blue Ocean, confirm the following:

  • The Bitbucket Branch Source plugin has been installed in Jenkins. You can also use the Git plugin if you use a Multibranch Pipeline job, but the Bitbucket Branch Source plugin is recommended.

  • Configure the Bitbucket Endpoint in Jenkins

  • The Bitbucket repository contains a Jenkinsfile (at the end of creating a new pipeline, Jenkins looks for this file in your Bitbucket repository. If it does not find it, it will give you the option of creating a Jenkinsfile).

Log into your Jenkins instance. If you do not have the Blue Ocean dashboard open, select Open Blue Ocean from the main Dashboard page. If you need to exit Blue Ocean, click the Exit button in the top right of the page, next to the Logout button.

The plugin used determines the configuration steps required to configure Jenkins to work with Webhook to Jenkins. Bitbucket Branch source plugin is the recommended plugin; however, you can use the Git plugin with a Jenkins multibranch pipeline job. Follow one of the workflows below, depending on the plugin you use.

Bitbucket Branch Source plugin

  1. Click New Pipeline.

  2. Select Bitbucket Cloud from the Where do your store your code? options.

    The Connect to Bitbucket section opens.

  3. Provide your Bitbucket username and the app password in the Username and Password fields and click Connect. This provides the logged-in Jenkins account access to your Bitbucket Cloud instance. See App Passwords to learn more about setting up an app password in Bitbucket Cloud.

  4. In the Which team does the repository belong to? section, click either:

    • Your Bitbucket account to create a Pipeline project for one of your Bitbucket repositories.

    • A team of which you are a member to create a Pipeline project for a Bitbucket repository located within this team.

  5. In the Choose a repository section, click the repository from which to build your Pipeline project. If your list of repositories is long, filter this list using the Search option.

  6. Click Create Pipeline.

Git plugin (use Multibranch Pipeline job)

  1. Click New Pipeline.

  2. Select Git from the Where do you store your code? options.

    The Connect to a Git repository section opens.

  3. Enter the Bitbucket Repository URL. If required, provide your Bitbucket username and the app password in the Username and Password fields. This provides the logged-in Jenkins account access to your repository.

  4. Click Create Pipeline.

Blue Ocean scans your local repository for a Jenkinsfile. If it doesn’t find one, you are prompted to create one.