Environment variables

These variables are available when a script gets executed.

Common variables #

Variable name Description
BB_HOOK_TRIGGER_ID The action that triggered the hook. For example: branch-create, pull-request-merge, or push.
BB_HOOK_TYPE Whether it is a pre or post-style hook. Value: PRE or POST.
BB_IS_DRY_RUN Whether it is a dry run. Value: true or false.
BB_PROJECT_KEY The repository’s project key.
BB_REPO_SLUG The repository slug.
BB_REPO_IS_FORK Whether the repository is a fork. Value: true or false.
BB_REPO_IS_PUBLIC Whether the repository is public. Value: true or false.
BB_BASE_URL The Bitbucket Server base URL.
BB_REPO_CLONE_SSH The SSH URL for cloning the repository. If SSH clones are disabled this does not need to be set.
BB_REPO_CLONE_HTTP The HTTP URL to clone the repository. If HTTP clones are disabled this does not need to be set.
BB_USER_NAME The username of the user that triggered the script.
BB_USER_DISPLAY_NAME The full name of the user that triggered the script.
BB_USER_EMAIL The email address of the user that triggered the script.
BB_USER_PERMISSION The highest permission level for the repository or system of the user that triggered the script. For example: REPO_WRITE, REPO_ADMIN, ADMIN, SYS_ADMIN.

Merge variables #

Variable name Description
BB_FROM_PROJECT_KEY The repository’s project key.
BB_FROM_REPO_SLUG The repository slug.
BB_FROM_REPO_IS_FORK Whether the repository is a fork. Value: true or false
BB_FROM_REPO_IS_PUBLIC Whether the from repository is public. Value: true or false
BB_FROM_REF The source ref for the merge.
BB_FROM_HASH The hash of the source ref for the merge.
BB_FROM_REPO_CLONE_SSH The SSH URL for cloning the repository. If SSH clones are disabled this does not need to be set.
BB_FROM_REPO_CLONE_HTTP The HTTP URL to clone the repository. If HTTP clones are disabled this does not need to be set.
BB_MERGE_HASH The merge commit hash. If it is a dry run this will be empty (i.e. BB_IS_DRY_RUN is true).
BB_MERGE_IS_CROSS_REPO Whether the merge is cross-repository. Value: true or false
BB_MERGE_STRATEGY_ID The strategy used for the merge. For example: ff, rebase-ff-only, squash
BB_TO_REF The target ref for the merge.
BB_TO_HASH The hash of the target ref for the merge.

Pull request variables #

Variable name Description
BB_PULL_REQUEST_ID The pull request ID (scoped to the repository).
BB_PULL_REQUEST_AUTHOR_USER_NAME The username of the pull request author.
BB_PULL_REQUEST_AUTHOR_USER_DISPLAY_NAME The full name of the pull request author.
BB_PULL_REQUEST_AUTHOR_USER_EMAIL The email address of the pull request author.
BB_PULL_REQUEST_AUTHOR_USER_PERMISSION The highest permission level of pull request author for the target repository or system For example: REPO_READ, REPO_WRITE, REPO_ADMIN, ADMIN, SYS_ADMIN

Source: https://developer.atlassian.com/server/bitbucket/how-tos/write-hook-scripts/

Bitbucket 3.X, 4.X and 5.X Pull Request Variables #

NOTE: These environment variables are used only for 3.X, 4.X and 5.X versions of Bitbucket.

Variable name Description
PULL_REQUEST_FROM_HASH The hash of the source ref for the merge
PULL_REQUEST_FROM_ID The source ref for the merge.
PULL_REQUEST_FROM_BRANCH The source pull request branch name
PULL_REQUEST_FROM_REPO_ID The source repository ID
PULL_REQUEST_FROM_REPO_NAME The source repository name
PULL_REQUEST_FROM_REPO_PROJECT_ID The source repository project ID
PULL_REQUEST_FROM_REPO_PROJECT_KEY The source repository project key (used for URL)
PULL_REQUEST_FROM_REPO_SLUG The source repository slug (used for URL)
PULL_REQUEST_FROM_SSH_CLONE_URL The URL with ssh protocol for git clone of source repository
PULL_REQUEST_FROM_HTTP_CLONE_URL The URL with http protocol for git clone of soruce repository
PULL_REQUEST_URL The URL of the pull request
PULL_REQUEST_ID The pull request ID
PULL_REQUEST_TITLE The title of the pull request
PULL_REQUEST_VERSION The resource version of the pull request
PULL_REQUEST_AUTHOR_ID The unique ID of the user created the pull request
PULL_REQUEST_AUTHOR_DISPLAY_NAME The name of the user created the pull request usedfor UI
PULL_REQUEST_AUTHOR_NAME The name of the user created the pull request
PULL_REQUEST_AUTHOR_EMAIL The email of the user created the pull request
PULL_REQUEST_AUTHOR_SLUG The slug (used for URLs) of the user created the pull request
PULL_REQUEST_TO_HASH The hash of the target ref for the merge
PULL_REQUEST_TO_ID The target ref for the merge.
PULL_REQUEST_TO_BRANCH The target pull request branch name
PULL_REQUEST_TO_REPO_ID The target repository ID
PULL_REQUEST_TO_REPO_NAME The target repository name
PULL_REQUEST_TO_REPO_PROJECT_ID The target repository project ID
PULL_REQUEST_TO_REPO_PROJECT_KEY The target repository project key (used for URL)
PULL_REQUEST_TO_REPO_SLUG The target repository slug (used for URL)
PULL_REQUEST_TO_SSH_CLONE_URL The URL with ssh protocol for git clone of target repository
PULL_REQUEST_TO_HTTP_CLONE_URL The URL with http protocol for git clone of soruce repository