bitbucket integration.html

On this page

The Eyes-Bitbucket integration builds on the branching capabilities in Eyes, and on the Bitbucket pull request and commit functionality.

Eyes supports multiple branches, each of which can consist of multiple test baselines. This lets you create a new branch based on an existing branch, make independent updates to the baselines in each branch, compare branches to detect conflicts, and then merge the baselines in each branch.

Bitbucket integrates with Eyes in the following aspects:

Setting up the Eyes Bitbucket Integration

You can integrate Bitbucket with Applitools Eyes using the Bitbucket public cloud (bitbucket.org) or a private Bitbucket server.

If the Bitbucket server or data center are deployed behind a company firewall, you need to whitelist inbound HTTPS traffic from the Eyes server to your Bitbucket server. If you use the Eyes Public server, the Eyes server is https://eyes.applitools.com. If you have a dedicated on-prem server, enter a URL in the format https://<My Organization>.eyes.applitools.com.

If you cannot whitelist the Eyes server then you should use the Applitools proxy server, for details see Configuring Bitbucket integration with a proxy server.

The Bitbucket repository access token requires full Eyes team administration privileges.

Enabling Bitbucket integration

  1. Navigate to the Admin Panel

  2. On the Admin panel, click on the Teams tile

  3. Click on the name of the team you want to configure.

  4. On the Integrations tab, click Bitbucket.

  5. If you use the public Bitbucket server, select bitbucket.org. If you use a private Bitbucket server, click Add and enter the URL of the Bitbucket server. You must have authorization to add and remove webhooks for the repositories that you want Eyes to be integrated with.

  6. Click the Manage repositories button.

  7. If you use a public cloud, click sign in with Bitbucket and give Bitbucket access to the repository. If you use a private Bitbucket server, in the Manage repositories window, enter your PAT and click Apply.

Configuring Your CI

Once you have set up Bitbucket integration, you need to set up your CI to configure the Eyes SDK with information related to the Bitbucket pull request or commit request. To allow the Eyes Batch to integrate data received from the Bitbucket server, you need to set the following Environment variables:

You also need to set the following Build configuration:

APPLITOOLS_BATCH_ID - The Commit SHA of the current build. This also must be set as an environment variable before running Eyes tests.

If Eyes cannot recognize the End of Build event, you also need to add a cURL command to notify Eyes when all builds are complete. For details, see Notifying Eyes when a build is complete.

Bitbucket Pipelines

Working With The Bitbucket Integration

Once your system is configured to work with Bitbucket, use your CI and Bitbucket in the usual way. A CI job is normally triggered by a push to your repository, which then runs your visual UI tests.

Pull request workflow

When there is an open pull request, Eyes adds the following functionality to your Bitbucket workflow:

Reviewing and resolving branch

Merging an Eyes source branch with a target branch results in adding new baselines to the target branch or updating its existing baselines according to baseline changes found in the source branch. Changes can include both updated baseline images and new, changed, or removed annotations (e.g. an added ignore region).

When working on a branch that is a child of another branch (the parent branch) and the child branch doesn't have a baseline, Eyes will use a fallback baseline from the parent branch.

Eyes knows how to compare two baselines and determine whether they can be merged automatically or whether user intervention is required. For example, an ignore region added to a source baseline step that did not change in the target baseline can be automatically added to the target baseline, but if another ignore region was added to the same step in the target baseline, user intervention is required to determine whether to keep only one of the added regions or both of them.

Commit push workflow

When a commit is pushed to a branch, Eyes adds the following functionality to your Bitbucket workflow:

Bitbucket Proxy Service

Eyes/Bitbucket integration requires two ways communication between the Eyes server and the Bitbucket server.

Communication from the Eyes server to the Bitbucket server is needed during the setup phase, when you select repositories to integrate with; the Eyes server uses the Bitbucket API to create webhooks in the selected repositories, the webhooks send all the relevant Bitbucket events to Eyes. The Bitbucket API also is used to update the status when an Eyes batch is completed and the status needs to be updated on the Bitbucket commit or pull request.

Communication from the Bitbucket server to the Eyes server is needed when events are sent by the webhooks to the Eyes server.

If your Bitbucket server is protected behind a firewall, and you cannot add a custom rule that exposes the relevant Bitbucket APIs so that Eyes can call them, you can use the Eyes-scm application to create webhooks on the relevant Bitbucket repositories.

Installation

Prerequisites

Before installing the proxy service, you must have:

One-time setup

Set up the following environment variables so that they are available to the proxy service.

# set the Eyes server URL to your server
EYES_SERVER_URL=<https://myorganizationeyesapi.applitools.com>
#set the Eyes organization ID
EYES_ORG_ID=<org ID>
# set the HTTP port the proxy service should use (optional - default is 4000)
PORT=<1234>

To install the proxy server run the following from any command shell:

npm i -g @applitools/eyes-scm

Running the proxy service

Configuration prerequisites

To set up Eyes-scm you need the following:

Starting the proxy service

Use the following command to start the server:

eyes-scm

Configuring repositories and access credentials

The first time you run the server, you need to define the repositories you want Eyes to access and provide the necessary Eyes and SCM credentials. You do this by starting the proxy service and accessing it with a browser.

  1. Make sure the proxy service is running.

  2. Select Bitbucket as the source control management system.

  3. Enter an Eyes API key with Team Admin rights and full privileges.

  4. Click Next

  5. A list of any SCM servers that have already been configured is displayed. Select an existing server or click Add a new server and enter the URL of the server.

  6. The first time you interact with the server, no repositories will have been enabled for Eyes access. Click Manage Repositories to select the repositories that you want to enable Eyes access to.

  7. Click Next.

  8. A list of repositories on the SCM server appears. The first time you configure the proxy service, all the repositories will be disabled. Click on the toggle next to the repository that you want Eyes to access to provide a Personal access token (PAT) for repositories that are disabled, or to change the PAT for repositories that are already enabled.

  9. Click Next. and enter the PAT for the repository. You can obtain the PAT value from Bitbucket.

  10. Click Save.

If the PAT is valid, the repository you selected will be in the enabled state. You can now enable any other repositories that you want to allow Eyes to access, and then exit from the browser.

Enabling Applitools logs in Bitbucket Pipelines

For Bitbucket Pipelines, add the following to your .bitbucket-pipelines.yml to enable Applitools logs and store them as artifacts:

- step:
    name: Visual Tests
    script:
      - export APPLITOOLS_SHOW_LOGS=true
      - export APPLITOOLS_LOG_DIR=logs/
      - npm test
    artifacts:
      - logs/**

If your Bitbucket Pipelines job runs inside Docker, logs written to APPLITOOLS_LOG_DIR can be lost when the container exits unless that path is mounted to the workspace.

Example Docker command:

docker run \ 
  -e APPLITOOLS_SHOW_LOGS=true \ 
  -e APPLITOOLS_LOG_DIR=/usr/src/app/logs \ 
  -v ${WORKSPACE}/applitools-logs:/usr/src/app/logs \ 
  your-image-name

Use the workspace path variable for your Bitbucket runner.