Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Default branch name

Brigitte Bedard March 6, 2025

How can I get the default branch name from inside a pipeline?  Our default branch name changes with every release.

I would like to be able to diff against the default branch to decide what part of the test suite to run when a new branch is pushed into the repo and before a PR is issued.

I looked everywhere and could not find it.  If it does not exist, it would be nice to make this available as a REPO variable accessible from inside the pipeline.

1 answer

0 votes
Mark C
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 9, 2025

Hi @Brigitte Bedard

Thank you for reaching out to the community.

Could you confirm if you're referring to the default branch name that is configured in your repository advanced settings?

Regards,
Mark C

Brigitte Bedard March 10, 2025

yes, that one

Mark C
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 11, 2025

Thanks for the info, @Brigitte Bedard

Unfortunately, default main branch is not available as part of default environment variables in Bitbucket Cloud Pipelines.

You can, however, try to get the data by using the below API endpoint extracting the "mainbranch" field value and saving it as an environment variable in your build.

/repositories/{workspace}/{repo_slug}

Reference: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-repositories/#api-repositories-workspace-repo-slug-get

Here's also an example on how to do that: https://confluence.atlassian.com/bbkb/obtaining-step-names-as-environment-variables-in-bitbucket-cloud-pipelines-1365016813.html

Regards,
Mark C

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin Site Admin
TAGS
AUG Leaders

Atlassian Community Events