Hi everyone,
I’m configuring Bitbucket Pipelines to perform automated semantic versioning and releases.
Context
-
Repository hosted on Bitbucket Cloud
-
masterbranch is protected:-
Direct pushes are disabled
-
Changes must come through Pull Requests
-
-
This protection is intentional and should remain in place
What the pipeline does
After a PR is merged into master, the pipeline:
-
Computes the next semantic version
-
Updates a version file (e.g.
__version__) -
Creates a new commit with the version bump
-
Attempts to push that commit back to
master -
Creates and pushes a Git tag
Authentication setup
-
Git operations use SSH (
git@bitbucket.org:workspace/repo.git) -
I’ve created a repository-level access token and exposed it to the pipeline
-
Token scopes include:
-
repository:write -
pullrequest:write -
pipeline:write -
runner:write
-
Problem
The pipeline can:
- Clone and fetch the repository successfully
But when it tries to push the version bump commit to master, it fails with:
remote: Permission denied to update branch master.
! [remote rejected] master -> master (pre-receive hook declined)
Questions
-
Is it actually possible for Bitbucket Pipelines to push commits directly to a protected branch like
master, even with a repository access token that hasrepository:write? -
Do repository access tokens bypass branch restrictions, or are branch restrictions always enforced regardless of token scopes?
-
Is the intended solution to:
-
Explicitly allow the pipeline identity to bypass branch restrictions, or
-
Avoid direct pushes entirely and instead have the pipeline create and merge a release PR?
-
-
Is there a recommended or cleaner approach for implementing automated version bumps on protected branches in Bitbucket Cloud?
I want to keep master protected, but still allow fully automated releases without manual intervention.
Thanks in advance for any guidance.
Best regards,
Pau
EDIT: Currently I’ve solved it by toggling branch restrictions via API in the release script, but I don’t think this is a valid permanent solution (neither an elegant one).