Bitbucket metrics
Introduction to metrics and good practices
Start with the outcome first
Common metrics
- Lead time
- Churn
- Impact
- Efficiency
Here is a great article that talks more about the different metrics.
DORA metrics
- Lead time for changes: What is the lead time for code changes from the point when code is checked in to the point it is released to production?
- Deployment frequency: How often and how fast do you ship to production?
- Time to restore service: When an incident is detected, how long does it take to remediate and restore the service?
- Change failure rate: How often do deployment failures occur in production that require immediate remedy or rollback?
Check out the following post to learn more about DORA and additional DevOps metrics: DevOps metrics
See how Jira Software helps you track key DevOps metrics like cycle time and deployment frequency with the demos on the following Atlassian Community page: All things DevOps Metrics: June 2021 Roundup!
Methods of collecting metrics
Add-ons
Name | Supported? | Instance | Atlassian Verified Vendor? | Comments |
---|---|---|---|---|
SERVERDATA CENTERCLOUD | + Cloud Security participant | This add-on provides a number of graphs and reports in the Bitbucket user interface, including pull request reports and commit reports. | ||
SERVERDATA CENTER | This add-on provides a number of charts that visualize contributions and repository activity within the Bitbucket user interface. | |||
SERVERDATA CENTER | This add-on provides an integration that allows you to pull metrics from Bitbucket into Prometheus. |
REST API
For a tutorial on using REST APIs, including a simple example of retrieving repository commits, check out this page.
/rest/api/1.0/admin/users
Retrieves users, including information about last authentication (can be used to identify inactive users).
1{2 "size": 1,3 "limit": 25,4 "isLastPage": true,5 "values": [6 {7 "name": "jcitizen",8 "emailAddress": "jane@example.com",9 "id": 101,10 "displayName": "Jane Citizen",11 "active": true,12 "slug": "jcitizen",13 "type": "NORMAL",14 "directoryName": "Stash Internal Directory",15 "deletable": true,16 "lastAuthenticationTimestamp": 1368145580548,17 "mutableDetails": true,18 "mutableGroups": true19 }20 ],21 "start": 022}
/rest/api/1.0/projects
Retrieves projects that the currently authenticated user has permission to view (can be used by an admin role with global visibility to get a list of all projects in Bitbucket for further processing).
1{2 "size": 1,3 "limit": 25,4 "isLastPage": true,5 "values": [6 {7 "key": "PRJ",8 "id": 1,9 "name": "My Cool Project",10 "description": "The description for my cool project.",11 "public": true,12 "type": "NORMAL",13 "link": {14 "url": "http://link/to/project",15 "rel": "self"16 },17 "links": {18 "self": [19 {20 "href": "http://link/to/project"21 }22 ]23 }24 }25 ],26 "start": 027}
/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/forks
Retrieves repositories that have been forked from a supplied repository.
/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/branches
Finds branches of a repository matching a supplied text pattern.
/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/commits
Retrieves commits from a given starting commit or between two commits.
/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/commits/{commitId}/pull-requests
Retrieves pull requests containing the supplied commit.
/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/participants
Retrieves participant users for all pull requests to or from the supplied repository.
/rest/api/1.0/repos
Retrieves repositories based on query parameters.
REST API sample script (Python 2)
1import requests,json23# Display the list of projects, repos, branches, and last commit on each branch.4print "Getting list of projects in Bitbucket ..."5projects = requests.get("http://bitbucket.bnc.com/rest/api/1.0/projects",auth=('userid','password')).json()6print "There are", projects["size"], "projects in Bitbucket:"78# For each project, list its repos ... 9for i in range(projects["size"]):10 repos = requests.get("http://bitbucket.company.com/rest/api/1.0/projects/"+projects["values"][i]["key"]+"/repos",auth=('userid','password')).json()11 print " ",projects["values"][i]["key"], ":", projects["values"][i]["name"], ":", repos["size"], "repositories:"1213 # For each repo, list its branches ...14 for j in range(repos["size"]):15 branches = requests.get("http:bitbucket.company.com/rest/api/1.0/projects/"+projects["values"][i]["key"]+"/repos/"+repos["values"][j]["slug"]+"/branches",auth=('userid','password')).json()16 print " ",repos["values"][j]["name"], ":", repos["values"][j]["slug"], ":", branches["size"], "branches."1718 # For each branch, list the last commit on that branch ...19 for k in range(branches["size"]):20 commits = requests.get("http://bitbucket.company.com/rest/api/1.0/projects/"+projects["values"][i]["key"]+"/repos/"+repos["values"][j]["slug"]+"/commits?until="+branches["values"][k]["displayId"],auth=('userid','password')).json()21 print " ",branches["values"][k]["displayId"], ":"22 print " ", commits["values"][0]["displayId"], ":", commits["values"][0]["author"]["name"], ":", commits["values"][0]["author"]["emailAddress"]
Git repository statistics
Additional resources
- Improve
- Learn more about DORA and additional DevOps metrics: DevOps metrics
- Atlassian Community: All things DevOps Metrics: June 2021 Roundup!
- Measure and quantify the benefits of your DevOps practices with our Advanced DevOps Guide
- Automate
Was this content helpful?
Connect, share, or get additional help
Atlassian Community