Bitbucket Pipelines

Run Tabnine CLI on every Bitbucket pull request to automate code review, documentation, test generation, and more.

Overview

The Tabnine Bitbucket Pipeline step runs the Tabnine CLI Agent on pull request events. The included configuration provides a comprehensive code review prompt that analyzes the PR diff and posts a summary comment and inline comments directly on the pull request using the Bitbucket API. You can customize the prompt to automate any task — see Customizing the Prompt.

Prerequisites

  • A Bitbucket repository with Pipelines enabled

  • A Tabnine account with Agents enabled

  • TABNINE_KEY - Tabnine Personal access token

  • BB_API_TOKEN - A Bitbucket access token with pullrequest:write and repository:read scopes

Quick Setup

1

Add repository variables

Go to your repository's Repository Settings > Pipelines > Repository variables and add:

Variable
Value
Options

TABNINE_KEY

Tabnine Personal Access Token

✅ Secured

BB_API_TOKEN

Bitbucket access token

✅ Secured

2

Add the pipeline configuration

Copy the bitbucket-pipelines.yml from the tabnine-pr-agent repositoryarrow-up-right to the root of your Bitbucket repository.

If you already have a bitbucket-pipelines.yml, merge the pull-requests section into your existing configuration:

bitbucket-pipelines.yml
image: node:20

pipelines:
  pull-requests:
    '**':
      - step:
          name: Tabnine Code Review
          script:
            - export TABNINE_HOST="${TABNINE_HOST:-https://console.tabnine.com}"
            - export TABNINE_MODEL_ID="${TABNINE_MODEL_ID:-}"

            # Input validation
            - |
              if [ -z "$TABNINE_KEY" ]; then
                echo "Error: TABNINE_KEY not set"
                exit 1
              fi
              if [ -z "$BB_API_TOKEN" ]; then
                echo "Error: BB_API_TOKEN not set"
                exit 1
              fi

            # Install dependencies
            - apt-get update -qq && apt-get install -y -qq curl git jq > /dev/null 2>&1

            # Install Tabnine CLI
            - |
              curl -fsSL "$TABNINE_HOST/update/cli/installer.mjs" -o installer.mjs
              node installer.mjs "$TABNINE_HOST"

            # Configure and run review
            # ... (see full configuration link below)

See the full configurationarrow-up-right for the complete pipeline including authentication setup and the review prompt.

3

Open a pull request

Push the configuration and open a PR. The Tabnine Code Review will run automatically.

Configuration

Required Repository Variables

Variable
Description

TABNINE_KEY

Tabnine authentication credentials (PAT). Mark as Secured.

BB_API_TOKEN

Bitbucket access token with pullrequest:write and repository:read scopes. Mark as Secured.

Optional Repository Variables

Variable
Default
Description

TABNINE_HOST

https://console.tabnine.com

Tabnine host URL (for self-hosted / EMT installations)

TABNINE_MODEL_ID

Model ID for the AI agent. If empty, uses the system default from the admin console.

Bitbucket Access Token

The BB_API_TOKEN is used by the agent to interact with the Bitbucket REST API — fetching PR details, reading diffs, and posting comments.

Creating an access token:

1

Go to Repository Settings > Access tokens (repository-level) or your Personal Settings > App passwords (account-level)

2

Create a token with pullrequest:write and repository:read scopes

3

Add it as a repository variable named BB_API_TOKEN and mark it as Secured

circle-info

Repository access tokens are preferred over personal app passwords for CI/CD use, as they are scoped to a single repository.

How It Works

1

Validate inputs

Checks that TABNINE_KEY and BB_API_TOKEN are set.

2

Install dependencies

Installs Tabnine CLI and required tools (curl, git, jq).

3

Configure authentication and settings

Sets up authentication and any pipeline-specific environment variables.

4

Resolve destination commit SHA

Uses the Bitbucket API to resolve the destination branch commit SHA.

5

Clean up previous comments

Removes previous Tabnine PR Bot comments from the PR.

6

Run the review

Fetches the PR diff via the Bitbucket API (api.bitbucket.org/2.0), analyzes the code, and posts summary and inline comments.

The pipeline uses these Bitbucket predefined variables automatically:

  • BITBUCKET_WORKSPACE — Workspace slug

  • BITBUCKET_REPO_SLUG — Repository slug

  • BITBUCKET_PR_ID — Pull request ID

  • BITBUCKET_COMMIT — Head commit SHA

  • BITBUCKET_PR_DESTINATION_BRANCH — Destination branch name

Important Notes

circle-exclamation
circle-info

Unlike GitHub Actions, Bitbucket Pipelines does not have a built-in continue-on-error equivalent at the step level. The pipeline step will fail if the review encounters an error. Consider wrapping the review command in a script that always exits 0 if you want advisory-only behavior.

Customization

Reviewing Only Specific Branches

Change the glob pattern to match only PRs targeting specific branches:

Using a Specific Model

Set the TABNINE_MODEL_ID repository variable, or set a default directly in the pipeline:

Self-Hosted / EMT Installations

Set the TABNINE_HOST repository variable, or override it in the pipeline script:

Troubleshooting

chevron-right"Error: TABNINE_KEY not set"hashtag

The repository variable is missing or empty.

Solution: Add TABNINE_KEY in Repository Settings > Pipelines > Repository variables. Mark it as Secured.

chevron-right"Error: BB_API_TOKEN not set"hashtag

The repository variable is missing or empty.

Solution: Create a Bitbucket access token with pullrequest:write and repository:read scopes and add it as a repository variable named BB_API_TOKEN.

chevron-rightPipeline does not run on pull requestshashtag

Possible causes:

  • Pipelines are not enabled for the repository — go to Repository Settings > Pipelines > Settings and enable them

  • The pull-requests section is missing or misconfigured in bitbucket-pipelines.yml

  • The PR target branch does not match the glob pattern

chevron-rightNo comments appear on the PRhashtag

Possible causes:

  • The BB_API_TOKEN lacks pullrequest:write scope

  • The PR diff is empty or contains only low-risk changes

  • Check the pipeline logs for API errors

See Also

Last updated

Was this helpful?