Environment Variables
Environment variables allow you to configure the CLI without storing credentials in files. This is especially useful for CI/CD pipelines and automation scripts.
Available Variables
Section titled “Available Variables”| Variable | Description | Example |
|---|---|---|
BB_USERNAME | Your Bitbucket username | myuser |
BB_API_TOKEN | Your Bitbucket API token | ATBB... |
NO_COLOR | Disable color output globally | 1 |
FORCE_COLOR | Force-enable color output globally | 1 |
Configuration Priority
Section titled “Configuration Priority”Repository context is resolved in this order (highest priority first):
- Command-line flags (
--workspace,--repo) - Git repository context (detected from remote URL)
- Configuration file (
defaultWorkspace)
Authentication credentials are resolved from:
- Configuration file (
~/.config/bb/config.jsonon macOS/Linux,%APPDATA%\bb\config.jsonon Windows) - Environment variables (
BB_USERNAME,BB_API_TOKEN) when runningbb auth login
For color output, precedence is:
--color(force color on)FORCE_COLOR--no-colorNO_COLOR
Authentication with Environment Variables
Section titled “Authentication with Environment Variables”Login from Environment Variables
Section titled “Login from Environment Variables”When environment variables are set, bb auth login uses them automatically:
export BB_USERNAME=myuserexport BB_API_TOKEN=ATBB_your_token_here
bb auth login # Uses env vars, no promptsNon-Interactive Usage
Section titled “Non-Interactive Usage”For scripts and CI/CD, set both variables before running commands:
export BB_USERNAME=myuserexport BB_API_TOKEN=ATBB_your_token_here
bb auth loginbb pr list -w myworkspace -r myrepoShell Configuration
Section titled “Shell Configuration”Add to ~/.bashrc or ~/.bash_profile:
export BB_USERNAME="your-username"export BB_API_TOKEN="your-api-token"Then reload:
source ~/.bashrcAdd to ~/.zshrc:
export BB_USERNAME="your-username"export BB_API_TOKEN="your-api-token"Then reload:
source ~/.zshrcAdd to ~/.config/fish/config.fish:
set -gx BB_USERNAME "your-username"set -gx BB_API_TOKEN "your-api-token"Then reload:
source ~/.config/fish/config.fishPowerShell
Section titled “PowerShell”Add to your PowerShell profile ($PROFILE):
$env:BB_USERNAME = "your-username"$env:BB_API_TOKEN = "your-api-token"Temporary Session
Section titled “Temporary Session”Set variables for a single terminal session:
# Linux/macOSexport BB_USERNAME=myuserexport BB_API_TOKEN=ATBB_token
# Windows Command Promptset BB_USERNAME=myuserset BB_API_TOKEN=ATBB_token
# Windows PowerShell$env:BB_USERNAME = "myuser"$env:BB_API_TOKEN = "ATBB_token"Or inline with a single command:
BB_USERNAME=myuser BB_API_TOKEN=ATBB_token bb auth login && bb pr list -w workspace -r repoDocker Usage
Section titled “Docker Usage”Pass environment variables to containers:
docker run -e BB_USERNAME=myuser \ -e BB_API_TOKEN=ATBB_token \ your-image sh -lc "bb auth login && bb pr list -w workspace -r repo"Or use an env file:
# .env.bb (not committed to git!)BB_USERNAME=myuserBB_API_TOKEN=ATBB_tokendocker run --env-file .env.bb your-image sh -lc "bb auth login && bb pr list -w workspace -r repo"CI/CD Examples
Section titled “CI/CD Examples”GitHub Actions
Section titled “GitHub Actions”name: PR Statuson: [push]
jobs: check-prs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4
- name: Setup Bun uses: oven-sh/setup-bun@v1 with: bun-version: latest
- name: Install Bitbucket CLI run: npm install -g @pilatos/bitbucket-cli
- name: List PRs env: BB_USERNAME: ${{ secrets.BB_USERNAME }} BB_API_TOKEN: ${{ secrets.BB_API_TOKEN }} run: | bb auth login bb pr list -w myworkspace -r myrepo --jsonGitLab CI
Section titled “GitLab CI”check-prs: image: oven/bun:latest variables: BB_USERNAME: $BB_USERNAME BB_API_TOKEN: $BB_API_TOKEN script: - npm install -g @pilatos/bitbucket-cli - bb auth login - bb pr list -w myworkspace -r myrepo --jsonBitbucket Pipelines
Section titled “Bitbucket Pipelines”image: oven/bun:latest
pipelines: default: - step: name: Check PRs script: - npm install -g @pilatos/bitbucket-cli - bb auth login - bb pr list -w $BITBUCKET_WORKSPACE -r $BITBUCKET_REPO_SLUG --jsonSecurity Best Practices
Section titled “Security Best Practices”-
Never commit tokens to git
- Add
.env*to your.gitignore - Use CI/CD secrets management
- Add
-
Use minimal token scopes
- Only grant permissions your script needs
- Read-only tokens for read-only operations
-
Rotate tokens regularly
- Especially after team member departures
- Use short-lived tokens when possible
-
Use secrets managers in production
- HashiCorp Vault
- AWS Secrets Manager
- Azure Key Vault
-
Audit token usage
- Review which tokens are active
- Revoke unused tokens