Integrations
How-to

Connect Bitbucket

Configure Bitbucket Cloud tool-provider credentials with repository profiles, the isolated aai-bitbucket Skill, and aai-cli commands.

For
Bitbucket administrators, Agent operators, and Organization administrators
On this page
  1. What you will configure
  2. Before you begin
  3. Choose the authentication method
  4. Plan token permissions
  5. 1. Create a Bitbucket API token
  6. 2. Collect repository details
  7. 3. Connect Bitbucket
  8. 4. Assign the Bitbucket Skill
  9. 5. Validate the connection
  10. 6. Verify Agent access
  11. Use the supported command groups
  12. Review a pull request through aai-cli
  13. Repository profiles
  14. Runtime behavior
  15. Use a Shared Credential
  16. Rotate or remove the credential
  17. API reference
  18. Troubleshooting
  19. Security practices
  20. Next steps
  • Integrations
  • 10–15 minutes
  • Requires a Bitbucket Cloud API token

Connect Bitbucket Cloud to let an Agent inspect repositories, branches, commits, source files, pull requests, review comments, and pipeline results.

Agent Barn stores the credential as an encrypted Agent Secret, and exposes Bitbucket operations to the Agent through the built-in Bitbucket Skill and aai-cli.

What you will configure

  1. Bitbucket account
  2. Scoped API token
  3. Encrypted Agent Secret
  4. Bitbucket Skill
  5. aai-cli profile
Complete setup path
Bitbucket account
        │
        ├── Scoped API token
        ├── Workspace ID
        └── Repository slugs
                  │
                  ▼
       Encrypted Agent Secret
                  │
                  ▼
        Built-in Bitbucket Skill
                  │
                  ▼
       aai-cli profile and commands

At the end of this guide, the Agent will have:

  • An encrypted bitbucket credential
  • The built-in Bitbucket Skill
  • A generated bitbucket-work profile
  • Explicit access to the repositories allowed by the Bitbucket account and API token
  • Commands for inspecting source, pull requests, branches, commits, and pipelines

Before you begin

You need:

  • An Agent Barn Organization
  • An existing Agent, or permission to hire one
  • Permission to update the Agent and manage its Secrets
  • A Bitbucket Cloud account with access to the intended repositories
  • The workspace ID and repository slugs you want the Agent to use
  • Permission to create an Atlassian API token

For a dedicated production Agent, use a dedicated Bitbucket account instead of a maintainer’s personal account. Grant that account access only to the repositories required by the Agent’s role.

Choose the authentication method

Use the credential pattern supported by the token you provision. Email plus an API token uses Basic authentication; workspace- and repository-scoped access tokens can use bearer authentication when the supplied token supports it.

A Basic-auth profile includes:

Runtime authentication
auth_type = "basic_api_token"
email = "agent@example.com"
api_token_secret = "bitbucket.api_token"

This matches Bitbucket Cloud’s supported API-token authentication using an Atlassian account email and API token.

If an Agent Barn screen still refers to “App password scopes,” treat that wording as legacy UI copy. Supply a scoped Bitbucket API token.

The validator checks authentication and, where possible, configured repository and pull-request access. Relevant access includes account or user read access when required by the token type, repository read access, pull-request read access, and pull-request write access when the Agent must post review comments. A token can authenticate successfully while still producing missing-scope warnings; an identity lookup alone does not prove access to every configured repository.

Official references:

Plan token permissions

Choose permissions based on what the Agent is expected to do.

Bitbucket permission Scope Use in Agent Barn Recommendation
User: Readread:user:bitbucketDisplays and validates the token owner’s identityRecommended
Repositories: Readread:repository:bitbucketLists repositories and reads branches, commits, and source filesRequired
Pull requests: Readread:pullrequest:bitbucketLists and reads pull requests, diffs, activity, and commentsRequired for review workflows
Pull requests: Writewrite:pullrequest:bitbucketCreates or changes pull requests and performs write operationsGrant only when the workflow requires it
Pipelines: Readread:pipeline:bitbucketReads pipelines, steps, and logsRequired only for CI inspection
Repositories: Writewrite:repository:bitbucketModifies repository contentNot required by the current read-oriented source workflow

A common code-review configuration is:

Read-oriented scopes
read:user:bitbucket
read:repository:bitbucket
read:pullrequest:bitbucket
read:pipeline:bitbucket

Add write:pullrequest:bitbucket only when the Agent must perform pull-request write operations beyond the actions covered by read access.

Create a Bitbucket API token

  1. Sign in to the Atlassian account that the Agent will use.
  2. Open the account’s Security settings.
  3. Select Create and manage API tokens.
  4. Select Create API token with scopes.
  5. Enter a descriptive name, such as agent-barn-code-reviewer.
  6. Set an expiration date that matches your credential-rotation policy.
  7. Select Bitbucket as the application.
  8. Select the permissions planned in the previous section.
  9. Restrict the token to the intended workspace if Atlassian offers that option in your account.
  10. Review the configuration and create the token.
  11. Copy the token immediately.

Bitbucket displays the token only once.

Collect repository details

Collect the following values before opening Agent Barn.

Value Example Where to find it
Workspace IDacme-engineeringThe workspace segment in a Bitbucket repository URL
Repository slugagent-barnThe final repository segment in the URL
Account emailagent@example.comThe Atlassian account that created the API token
API tokenREDACTEDThe token copied during creation

For this repository URL:

Repository URL
https://bitbucket.org/acme-engineering/agent-barn

Use workspace acme-engineering and repository agent-barn.

Enter a bare repository slug in Agent Barn. Do not enter the full URL or workspace/repository.

Correct

Accepted
agent-barn

Incorrect

Not accepted
https://bitbucket.org/acme-engineering/agent-barn
acme-engineering/agent-barn

The workspace ID can differ from the workspace’s display name. Use the value from the repository URL.

Connect Bitbucket

  1. In Agent Barn, open Agents.
  2. Select the Agent that needs Bitbucket access.
  3. Open the Agent’s Configuration.
  4. Select Keys & integrations.
  5. Select Edit.
  6. Under Integration credentials, add Bitbucket.
  7. Select Manual credential.
  8. Complete the Bitbucket fields.
  9. Apply the configuration.
Agent Barn field Required Value
Workspace (workspace)YesBitbucket workspace identifier
Repositories (repos)NoOptional list of bare repository slugs
Email (email)YesAccount email used when Basic authentication is required
API token (apiToken)YesSecret token or supported access token

Example:

Completed fields
Workspace
acme-engineering

Repositories
agent-barn
internal-platform

Email
agent@example.com

API token
••••••••••••••••

repos is a list, not a single repo field. Legacy credentials with one repository may be normalized into this list; new entries should always use repos. The API token is encrypted and write-only, so examples never display a real token.

If the Agent is running, use the website’s restart-aware apply flow. The updated credential and generated profile become available when the Agent starts again.

Assign the Bitbucket Skill

The aai-bitbucket Skill supplies instructions and command references; the Bitbucket Integration credential supplies authentication and generated profile configuration. Bitbucket is a tool Integration, not a Communication Connection.

  1. Open the Agent’s Skills configuration.
  2. Select Edit.
  3. Add the built-in Bitbucket Skill.
  4. Apply the change.
  5. Restart the Agent if prompted.

The mounted Skill’s canonical entry point is:

Mounted Skill
./skills/aai-bitbucket/SKILL.md
Isolated Bitbucket Skill bundle
aai-bitbucket/
├── SKILL.md
└── references/
    └── command-reference.md

The Agent should read ./skills/aai-bitbucket/SKILL.md before using Bitbucket. The supporting command reference belongs to that same bundle; the Skill is not one file inside a shared aai-cli directory. It documents the aai-cli bitbucket command group.

Assigning the Skill does not create, reveal, or grant a credential; adding a credential does not mutate the Skill. The bundled Skill declares Bitbucket as a required provider, which Agent configuration validates against available Integration credentials. Bitbucket is also eligible for the manual-entry Shared Credentials workflow.

Validate the connection

After saving the credential:

  1. Return to Keys & integrations.
  2. Find the configured Bitbucket credential.
  3. Select Validate.
  4. Review the validation status, identity, and missing scopes.
Status Meaning
ValidAuthentication succeeded and no checked scope is missing
WarningAuthentication succeeded, but the validator detected a missing permission
InvalidThe token was rejected, expired, unreachable, or could not access a required resource

A successful response resembles:

Response
{
  "validation_status": "valid",
  "validation_identity": "Agent Account (@agent-account)",
  "validation_error": null,
  "missing_scopes": []
}

A usable token with incomplete permissions can return:

Warning response
{
  "validation_status": "warning",
  "validation_identity": "Agent Account (@agent-account)",
  "validation_error": null,
  "missing_scopes": [
    "Repositories (read) scope missing"
  ]
}

Verify Agent access

Ask the Agent to identify its configured Bitbucket integration and inspect a known repository. For direct runtime verification, use commands like these inside the Agent environment.

List repositories:

Shell
aai-cli bitbucket repos list \
  --limit 3 \
  --profile bitbucket-work

Read repository metadata:

Shell
aai-cli bitbucket repos get acme-engineering/agent-barn \
  --profile bitbucket-work

Read the default branch:

Shell
aai-cli bitbucket branches get main \
  --owner acme-engineering \
  --repo agent-barn \
  --profile bitbucket-work

Read a source file:

Shell
aai-cli bitbucket source get main README.md \
  --owner acme-engineering \
  --repo agent-barn \
  --profile bitbucket-work

List pull requests:

Shell
aai-cli bitbucket prs list \
  --owner acme-engineering \
  --repo agent-barn \
  --state OPEN \
  --limit 5 \
  --profile bitbucket-work

Inspect recent pipelines:

Shell
aai-cli bitbucket pipelines list \
  --owner acme-engineering \
  --repo agent-barn \
  --limit 5 \
  --profile bitbucket-work

Successful command output is JSON. Errors are written to standard error as a JSON object, and return a non-zero exit code.

Use the supported command groups

aai-cli Bitbucket resources
aai-cli bitbucket repos
aai-cli bitbucket prs
aai-cli bitbucket branches
aai-cli bitbucket commits
aai-cli bitbucket source
aai-cli bitbucket pipelines

These commands list and inspect repositories, pull requests, branches, commits, source files and history, pipelines, steps, and logs. Pull-request commands also read diffs, diff statistics, commits, and activity, and can list, create, update, or delete comments. The Skill documents these commands; aai-cli performs the provider operation.

Review a pull request through aai-cli

  1. Run prs get to inspect pull-request metadata.
  2. Run prs diffstat to identify changed files.
  3. Use prs diff --output for a large diff.
  4. Use source get <commit> <path> for exact file contents.
  5. Use prs comments create only when the Agent’s policy permits review comments.
Representative review commands
aai-cli bitbucket prs get 42 --repo my-workspace/my-repo --profile bitbucket-work
aai-cli bitbucket prs diffstat 42 --repo my-workspace/my-repo --profile bitbucket-work
aai-cli bitbucket prs diff 42 --repo my-workspace/my-repo --output local/logs/pr-42.diff --profile bitbucket-work
aai-cli bitbucket source get <commit> <path> --repo my-workspace/my-repo --profile bitbucket-work

For an inline comment, use --inline-path and --inline-to for a line added in the new file, or --inline-from for a line removed from the old file. Do not use direct Bitbucket REST calls as the Agent interface.

Repository profiles

Agent Barn converts the repository list into one or more aai-cli profiles.

One repository

Workspace acme-engineering with repository agent-barn creates a single profile:

bitbucket-work → acme-engineering/agent-barn

Multiple repositories

Each additional repository adds a numbered profile: bitbucket-work-2, bitbucket-work-3, and so on.

No configured repository

bitbucket-work is still created, but without a default repo. Repository commands must pass --repo.

With three repositories configured, Agent Barn creates:

Profile mapping
bitbucket-work   → acme-engineering/agent-barn
bitbucket-work-2 → acme-engineering/internal-platform
bitbucket-work-3 → acme-engineering/documentation

The Agent’s generated tool context contains the authoritative mapping. Do not infer that a numbered profile refers to a particular repository without checking that mapping.

Because command-line values override profile defaults, the Agent can normally continue using bitbucket-work and pass the intended --owner and --repo explicitly:

Explicit target
--owner acme-engineering --repo agent-barn

Runtime behavior

When the Agent starts, Agent Barn:

  1. Decrypts the Bitbucket credential for the runtime.
  2. Writes the token to the encrypted aai-cli secret store.
  3. Generates the Bitbucket profile.
  4. Mounts the built-in Bitbucket Skill.
  5. Adds the profile mapping to the Agent’s tool context.

A generated profile resembles:

Generated profile
[profiles.bitbucket-work]
auth_type = "basic_api_token"
workspace = "acme-engineering"
repo = "agent-barn"
email = "agent@example.com"
api_token_secret = "bitbucket.api_token"

The token itself is not written into the profile. The profile references the encrypted secret name bitbucket.api_token.

The complete runtime path is:

Runtime path
Encrypted Bitbucket credential
              │
              ▼
         Agent start
              │
              ├── aai-cli encrypted secret store
              ├── bitbucket-work profile
              └── Bitbucket Skill files
                         │
                         ▼
                aai-cli bitbucket
                         │
                         ▼
                 Bitbucket Cloud API

Credential changes take effect after the Agent restarts.

Use a Shared Credential

An Organization administrator can create an Organization-owned Shared Credential for Bitbucket, and attach it to multiple Agents.

Use a Shared Credential when:

  • Multiple Agents should use the same dedicated Bitbucket service account
  • One administrator should rotate the token centrally
  • Individual Agent operators should not handle the token
  • The same workspace and repository defaults apply to several Agents

To attach one:

  1. Create or locate the Bitbucket Shared Credential in the Organization.
  2. Open the Agent’s Keys & integrations configuration.
  3. Add Bitbucket.
  4. Switch from Manual credential to Shared Credential.
  5. Select the intended credential.
  6. Apply the change, and restart the Agent if prompted.
  7. Validate the connection from the Agent.

An Agent can use either a manual Bitbucket credential or a Shared Bitbucket Credential, not both simultaneously.

Continue to Use shared credentials for the complete ownership and rotation model.

Rotate or remove the credential

Rotate a manual credential

  1. Create a replacement API token in Atlassian.
  2. Keep the old token active temporarily.
  3. Open the Agent’s Keys & integrations configuration.
  4. Replace the Bitbucket credential with the new token.
  5. Apply the change.
  6. Restart the Agent.
  7. Validate the new credential.
  8. Run a real repository command.
  9. Revoke the old token in Atlassian.

Because secret values are write-only, rotation replaces the complete credential content. Re-enter the workspace, repositories, email, and token.

Rotate a Shared Credential

Update the Organization-owned Shared Credential, validate it, and restart attached Agents so their runtime artifacts are regenerated.

Remove the credential

Before removing Bitbucket:

  1. Remove or replace any assigned Skill that requires Bitbucket.
  2. Stop the Agent, or use the website’s restart-aware apply flow.
  3. Open Keys & integrations.
  4. Mark the Bitbucket credential for removal.
  5. Apply the change.
  6. Restart and verify the Agent.

Agent Barn blocks removal when a remaining assigned Skill requires the bitbucket provider.

API reference

Add or replace a manual credential

The Agent must be stopped when using the raw update endpoint.

HTTP
PATCH /api/v1/organizations/{organization_id}/agents/{agent_id}
Content-Type: application/json
Request body
{
  "secrets": [
    {
      "provider": "bitbucket",
      "content": {
        "workspace": "acme-engineering",
        "repos": [
          "agent-barn",
          "internal-platform"
        ],
        "email": "agent@example.com",
        "apiToken": "REDACTED"
      }
    }
  ]
}

Attach a Shared Credential

Request body
{
  "shared_credentials": [
    {
      "shared_credential_id": "00000000-0000-0000-0000-000000000000"
    }
  ]
}

Validate the Agent credential

HTTP
POST /api/v1/organizations/{organization_id}/agents/{agent_id}/integrations/bitbucket/validate

The response includes:

Response
{
  "validation_status": "valid",
  "validation_identity": "Agent Account (@agent-account)",
  "validation_error": null,
  "missing_scopes": []
}

Remove the credential

Request body
{
  "removed_secret_providers": [
    "bitbucket"
  ]
}

Credential operations require access to the Agent and the appropriate update and secret-management permissions, including agent.secret.manage.

Troubleshooting

The Agent cannot find the Bitbucket command guidance

Skill, credential, or profile

Confirm the Bitbucket Integration exists for the Agent, the required Skill is assigned and published, and the Agent has started with the generated artifacts. Read ./skills/aai-bitbucket/SKILL.md and pass --profile bitbucket-work explicitly. If no repository is configured, include --repo; for several repositories, select the corresponding generated profile or pass an explicit repository identity.

Validation reports “Invalid API token or credentials”

Check the token type and email

Check that:

  • You created an API token with scopes for the Bitbucket application
  • Email is the Atlassian account email that owns the token
  • The token was copied completely
  • The token has not expired or been revoked
  • You did not enter an Atlassian account password
  • You did not enter a retired Bitbucket app password

Create a replacement token if the original token can no longer be retrieved.

Validation succeeds but repository commands return 403

A permission or membership gap

The token authenticated, but it lacks a required permission, or the account cannot access the repository. Check:

  • read:repository:bitbucket is selected
  • The account is a member of the target workspace, or has repository access
  • The token is allowed to access the target workspace
  • The workspace ID and repository slug are correct
  • Pull-request and pipeline permissions are present for those operations

Pull requests work but source files fail

Separate scopes

Pull-request access and repository access use separate scopes. Add read:repository:bitbucket.

The pull-request scope does not automatically grant access to repository source endpoints.

Source files work but pull requests fail

Repository Read is not enough

Add read:pullrequest:bitbucket. Repository Read does not include pull-request access.

Pipeline commands return 403

Pipelines has its own scope

Add read:pipeline:bitbucket. Repository Read does not include Bitbucket Pipelines.

The repository cannot be found

Check IDs and slugs

Confirm that:

  • Workspace contains the workspace ID, not its display name
  • Repositories contains a bare slug
  • --owner contains only the workspace ID
  • --repo contains only the repository slug
  • The token-owning account can open the repository in Bitbucket

aai-cli reports that the repository is missing

No default repository

No default repository was configured, or the command did not include --repo. Run the command with explicit values:

Shell
aai-cli bitbucket prs list \
  --owner acme-engineering \
  --repo agent-barn \
  --profile bitbucket-work

The wrong repository is used

Pass the target explicitly

Pass both the workspace and repository explicitly:

Explicit target
--owner acme-engineering --repo agent-barn

If using a numbered profile, consult the Agent’s generated integration mapping before selecting it.

Validation succeeds but runtime commands fail authentication

Bearer tokens do not match the profile

Confirm that you supplied a user-based Bitbucket API token and its Atlassian account email.

Workspace and repository access tokens use bearer authentication, while the current Agent Barn runtime profile uses basic_api_token. Replace the credential with an account API token for the supported end-to-end flow.

The credential cannot be removed

A Skill still requires it

A remaining assigned Skill requires Bitbucket.

Remove the Bitbucket Skill, or replace the dependent Skill, before removing the credential.

Changes are not visible to the Agent

Artifacts are produced at startup

Restart the Agent. Profiles, encrypted runtime Secrets, mounted Skills, and generated tool context are produced during Agent startup.

Security practices

  • Use a dedicated Bitbucket account for production Agents
  • Grant the account access only to required repositories
  • Create a separate API token for Agent Barn
  • Set an expiration date
  • Start with read scopes
  • Avoid repository write, admin, and delete scopes unless a documented workflow requires them
  • Use different credentials for different authorization boundaries
  • Treat the repository list as defaults, not access control
  • Prefer Shared Credentials when administrators should own rotation
  • Validate after every rotation
  • Test a real repository operation after validation
  • Revoke replaced or compromised tokens immediately
  • Never place a real token in documentation, source control, logs, prompts, or chat messages

Next steps

Documentation