-
Type:
Suggestion
-
Resolution: Unresolved
-
Component/s: Pipelines - Variables
-
None
-
1
Description:
Currently, Bitbucket Cloud allows repository admins to specify the "Main branch" (such as "master", "main", "develop", etc.) in the repository's Advanced settings. However, Bitbucket Pipelines does not expose this value as a built-in environment variable during pipeline execution.
Use Case:
Many teams use different naming conventions for their main branch across repositories (e.g., "main", "master", "develop"). In CI/CD pipelines, it is common to run certain steps (such as deployments, artifact generation, or security scans) only on the main branch.
At present, the only workaround is to manually define a repository variable (e.g., MAIN_BRANCH) and keep it in sync with the repository's main branch setting, which is error-prone and requires manual maintenance.
Feature Request:
Please introduce a built-in environment variable (e.g., BITBUCKET_MAIN_BRANCH) that exposes the repository's configured main branch name to Bitbucket Pipelines. This would allow pipeline scripts to easily and reliably determine if the current build is running on the main branch, regardless of its name.
Example:
script: - if [ "$BITBUCKET_BRANCH" = "$BITBUCKET_MAIN_BRANCH" ]; then # Run main-branch-only steps fi
Benefits:
- Reduces manual configuration and maintenance.
- Prevents errors due to mismatched branch names.
- Enables more robust and portable pipeline configurations across repositories.
References:
- [Variables and secrets | Bitbucket Cloud | Atlassian Support|https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/]