What it does
- Pull in CI: a
pull-requestspipeline runsstoaken export --check. - Push on publish: a Stoaken webhook sent as a Bitbucket Pipelines run calls Bitbucket's run-a-pipeline API. That starts the custom pipeline
stoaken-release, which exports the tokens, pushesstoaken/tokens, and can open a pull request.
Before you start
- A Stoaken API key and a
stoaken.config.jsonwithexports(see /docs/cli). - Brand Admin in Stoaken, on the Team plan.
- A Bitbucket repository access token with pipeline:write (Repository settings > Access tokens). Access tokens are sent as
Authorization: Bearer(docs). - Pipelines enabled on the repository.
Setup
- Add the secured repository variable
STOAKEN_TOKEN. Optionally addBB_PR_TOKEN, an access token withpullrequest:write, so the pipeline also opens the pull request. - Commit
bitbucket-pipelines.yml(template:bitbucketPipelines()insrc/lib/integrations/pipelines.ts). The custom pipeline must exist on the branch you name in step 3:
image: node:22
pipelines:
pull-requests:
'**':
- step:
script:
- npx --yes stoaken@latest export --check
custom:
stoaken-release:
- variables:
- name: STOAKEN_EVENT
- name: STOAKEN_RELEASE_ID
- name: STOAKEN_VERSION
- step:
script:
- npx --yes stoaken@latest export
# … commit + push stoaken/tokens, optional PR via the API- In Stoaken, go to Settings > Webhooks and choose Add a webhook:
- Send as: Bitbucket Pipelines run
- Address:
https://api.bitbucket.org/2.0/repositories/WORKSPACE/REPO/pipelines/ - Access token: the pipeline:write token. It's stored encrypted and never shown again.
- Branch: for example
main - Events: Release published.
Configuration
- Body sent:
{"target": {"type": "pipeline_ref_target", "ref_type": "branch", "ref_name": "<branch>", "selector": {"type": "custom", "pattern": "stoaken-release"}}, "variables": [...]}. - Variables:
STOAKEN_EVENT(release.published, orpingfor Send test, which the template skips),STOAKEN_RELEASE_IDandSTOAKEN_VERSION. - The token is only ever sent to
https://api.bitbucket.org/2.0/repositories/…/pipelines/, and the database enforces this.
Try it
- Send test should get 201 from Bitbucket and a short
stoaken-releaserun that stops at the ping check. - Send a sample with Release published runs the full update.
Troubleshooting
- 401/403: the token has expired or lacks pipeline:write.
- 404: the workspace or repository slug in the address is wrong.
- 400 "bitbucket-pipelines.yml not found" or no such pipeline: the branch you named has no
custom: stoaken-release. - Push refused: the branch is restricted. Allow the pipeline to push to
stoaken/tokens.
Limits
- Bitbucket Cloud only. Data Center has a different API and isn't supported.
- Pipelines minutes count against your Bitbucket plan.