How to Export Bitbucket Pipelines Minutes Usage Report in Bitbucket Cloud
Platform Notice: Cloud Only - This article only applies to Atlassian apps on the cloud platform.
Summary
Currently, Bitbucket Cloud does not have the functionality to show a report of the minutes used at the pipeline level or repository level. An open feature request is with our development team to include this within the platform. As an alternative, the build statistics pipe can be used to provide this information.
Solution
Option 1: Store the pipeline report as a TXT file artifact.
The file will be created in the BITBUCKET_CLONE_DIR directory. Here is a sample code snippet to configure this:
Here is a sample code snippet to configure this:
pipelines:
default:
- step:
name: "Pipeline Build Statistics"
artifacts:
- build-minutes.txt
script:
- pipe: atlassian/bitbucket-build-statistics:1.5.4
variables:
ATLASSIAN_ACCOUNT_EMAIL: $ATLASSIAN_ACCOUNT_EMAIL
ATLASSIAN_API_TOKEN: $ATLASSIAN_API_TOKEN
FILENAME: "build_usage.txt"
- ls $BITBUCKET_CLONE_DIR
- cat build_usage.txt
Option 2: Store the pipeline report as a JSON artifact:
The JSON file can be downloaded, and data can be programmatically processed. Here is a sample code snippet to configure this:
Here is a sample code snippet to configure this:
pipelines:
default:
- step:
name: "Pipeline Build Statistics"
artifacts:
- build-minutes.json
script:
- pipe: atlassian/bitbucket-build-statistics:1.5.4
variables:
ATLASSIAN_ACCOUNT_EMAIL: $ATLASSIAN_ACCOUNT_EMAIL
ATLASSIAN_API_TOKEN: $ATLASSIAN_API_TOKEN
FILENAME: "build_usage"
OUTPUT_FILE_FORMAT: "json"
- ls $BITBUCKET_CLONE_DIR
- cat build_usage.json
The Atlassian account email can be obtained here: https://bitbucket.org/account/settings/email/. You can find more info on API tokens and how to generate one here: https://support.atlassian.com/bitbucket-cloud/docs/api-tokens/. The token will need to have the scopes
read:repository:bitbucket
andread:pipeline:bitbucket
.The repository variables $ATLASSIAN_ACCOUNT_EMAIL and $ATLASSIAN_API_TOKEN hold these values and they are added in the repository settings.
This pipe will provide statistics for the last 30 days by default if the optional BUILD_DAYS component is not specified.
Was this helpful?