How to Export Bitbucket Pipelines Minutes Usage Report in Bitbucket Cloud
Platform Notice: Cloud Only - This article only applies to Atlassian products 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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
pipelines:
default:
- step:
name: "Pipeline Build Statistics"
artifacts:
- build-minutes.txt
script:
- pipe: atlassian/bitbucket-build-statistics:1.5.3
variables:
BITBUCKET_USERNAME: $BITBUCKET_USERNAME
BITBUCKET_APP_PASSWORD: $BITBUCKET_APP_PASSWORD
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
pipelines:
default:
- step:
name: "Pipeline Build Statistics"
artifacts:
- build-minutes.json
script:
- pipe: atlassian/bitbucket-build-statistics:1.5.3
variables:
BITBUCKET_USERNAME: $BITBUCKET_USERNAME
BITBUCKET_APP_PASSWORD: $BITBUCKET_APP_PASSWORD
FILENAME: "build_usage"
OUTPUT_FILE_FORMAT: "json"
- ls $BITBUCKET_CLONE_DIR
- cat build_usage.json
The username can be obtained here: https://bitbucket.org/account/settings/ and an app password can be generated from here: https://bitbucket.org/account/settings/app-passwords/
The repository variables $BITBUCKET_USERNAME and $BITBUCKET_APP_PASSWORD hold these values which 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?