Skip to main content

Bitbucket metrics

Introduction to metrics and good practices

Start with the outcome first

Before you even start looking at what metrics you want to use, you need to understand the outcome you're trying to achieve. Is it higher quality, increased productivity, or something else? Based on what the desired outcome is, you'll need to make certain decisions, and you'll need specific insights to help you make them. Those insights will ultimately determine what metrics you will use. You can read more about an outcome-driven framework (ODIM) here.

Common metrics

With that in mind, let's take a look at some commonly-used metrics that often help organizations drive toward their outcomes. Again, these metrics may or may not be relevant, depending on your particular outcomes. Whatever you do when picking your metrics, don’t just go with what is easy.
Engineers are uniquely skilled at building and solving difficult conceptual problems, so contributing code is one of the most important things that an engineer can do. That's why metrics around contributions (commits, code reviews, etc.) can be a key indicator of an engineer's effectiveness. If you see low engagement, you might want to think about why that is so. What factors are preventing the engineers from contributing? Are there too many interruptions during the week, inhibiting their ability to contribute? Try to identify possible causes, make changes to mitigate them, and watch the impact.
In addition to activity in Bitbucket, there are several additional metrics you can look at:
  1. Lead time
  2. Churn
  3. Impact
  4. Efficiency

Here is a great article that talks more about the different metrics.

DORA metrics

DevOps practitioners rely on four key metrics, developed by DORA, to measure the efficacy of their DevOps practices.
  • 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

The Bitbucket Server REST API can be used to extract information from a Bitbucket installation.

For a tutorial on using REST APIs, including a simple example of retrieving repository commits, check out this page.

Queries that might be of use include:

/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

You can also make use of core Git command line querying functionality — via git log — to extract information about commits, committers, branches, files, etc.

See: git log documentation

There also a number of third-party tools available that provide statistics and visualizations on a given Git repository:
  • GitStats - Git history statistic generator; provides information like repository age, file count, lines of code, authors, total commits, etc. Example output here.
  • Gitinspector - Similar information as above with slightly different visuals. Example output here.

Additional resources

Was this content helpful?

Connect, share, or get additional help

Atlassian Community