Skip to main content
Additional metadata can be sent up with your Bazel invocation to give BuildBuddy more information about your build.

Repository URL

BuildBuddy allows you to group invocations by the repository on which they were run. In order to perform this grouping, BuildBuddy needs the repository’s git url. There are three ways of providing this information to BuildBuddy:
The first method is simple - just provide the repo URL with Bazel’s build_metadata flag with the key REPO_URL. You can do this by adding the following line to your .bazelrc:
.bazelrc
build --build_metadata=REPO_URL=https://github.com/buildbuddy-io/buildbuddy.git

Git Branch

BuildBuddy allows you to group invocations by the git branch on which they were run. In order to perform this grouping, BuildBuddy needs the branch name.
You can provide the current git branch with Bazel’s build_metadata flag with the key BRANCH_NAME. You can do this by adding the flag to your bazel invocations:
--build_metadata=BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
You cannot add this particular flag to your .bazelrc file because it does not support parameter substitution. If you’re looking for a solution that supports your .bazelrc file, try the Workspace info method.

Commit SHA

You can provide the current commit SHA with Bazel’s build_metadata flag with the key COMMIT_SHA. You can do this by adding the flag to your bazel invocations:
--build_metadata=COMMIT_SHA=$(git rev-parse HEAD)
You cannot add this particular flag to your .bazelrc file because it does not support parameter substitution. If you’re looking for a solution that supports your .bazelrc file, try the Workspace info method.

Role

The role metadata field allows you to specify whether this invocation was done on behalf of a CI (continuous integration) system. If set, this enables features like Github commit status reporting (if a Github account is linked). For CI builds, you can add the following line to your .bazelrc and run your CI builds with the --config=ci flag:
.bazelrc
build:ci --build_metadata=ROLE=CI
This role will automatically be populated if the environment variable CI is set, which it is in most CI systems like Github Actions, CircleCI, Travis, Gitlab CI, BuildKite, Bitrise, and others.

Test groups

If using Github commit status reporting, you can use the test groups metadata field to specify how tests are grouped in your Github commit statuses. Test groups are specified as a comma separated list of test path prefixes that should be grouped together.
.bazelrc
build --build_metadata=TEST_GROUPS=//foo/bar,//foo/baz

Visibility

The visibility metadata field determines who is allowed to view your build results. By default, unauthenticated builds are publicly visible to anyone with a link, while authenticated builds are only available to members of your organization. You can override these default settings and make authenticated builds visible to anyone with a link by adding the following line to your .bazelrc:
.bazelrc
build --build_metadata=VISIBILITY=PUBLIC

User

By default a build’s user is determined by the system on which Bazel is run.
BuildBuddy will automatically pull your username from environment variables if you’re using a common CI platform like Github Actions, CircleCI, Travis, Jenkins, Gitlab CI, Bitrise, or BuildKite. The environment variables currently supported are USER, GITHUB_ACTOR, GITLAB_USER_NAME, BUILDKITE_BUILD_CREATOR, CIRCLE_USERNAME.
You can override this using build metadata or workspace info.

Build metadata

You can provide your user with Bazel’s build_metadata flag with the key USER. You can do this by adding the flag to your bazel invocations:
--build_metadata=USER=yourname

Workspace info

First, you’ll need to point your workspace_status_command flag at a workspace_status.sh file at the root of your workspace. You can do this by adding the following line to your .bazelrc.
.bazelrc
build --workspace_status_command=$(pwd)/workspace_status.sh
Then you’ll need to add a workspace_status.sh file to the root of your workspace that prints USER yourname.

Host

By default a build’s host is determined by the system on which Bazel is run. You can override this using build metadata or workspace info.

Build metadata

You can provide your user with Bazel’s build_metadata flag with the key HOST. You can do this by adding the flag to your bazel invocations:
--build_metadata=HOST=yourhost

Workspace info

First, you’ll need to point your workspace_status_command flag at a workspace_status.sh file at the root of your workspace. You can do this by adding the following line to your .bazelrc.
.bazelrc
build --workspace_status_command=$(pwd)/workspace_status.sh
Then you’ll need to add a workspace_status.sh file to the root of your workspace that prints HOST yourhost.

Pattern

By default a build’s pattern is determined by bazel command that is run. If the bazel command is:
bazel build //...
The pattern would be:
//...
You can override this using build metadata or workspace info.
This is generally only needed for advanced use cases where you want to display a more user friendly or information rich pattern in the UI than was originally used on the command line.

Build metadata

You can provide a custom pattern with Bazel’s build_metadata flag with the key PATTERN. You can do this by adding the flag to your bazel invocations:
--build_metadata=PATTERN=yourpattern

Workspace info

First, you’ll need to point your workspace_status_command flag at a workspace_status.sh file at the root of your workspace. You can do this by adding the following line to your .bazelrc.
.bazelrc
build --workspace_status_command=$(pwd)/workspace_status.sh
Then you’ll need to add a workspace_status.sh file to the root of your workspace that prints PATTERN yourpattern. You can add custom links to the BuildBuddy overview page using the BUILDBUDDY_LINKS build metadata flag. These links must be comma separated, and in the form [link text](https://linkurl.com). Urls must begin with either http:// or https://. Example:
--build_metadata=BUILDBUDDY_LINKS="[Search Github](https://github.com/search),[GCP Dashboard](https://console.cloud.google.com/home/dashboard)"

Tags

You can add multiple free-text tags to a build by passing a comma-separated string to the TAGS build metadata flag. Example:
--build_metadata=TAGS="foo,bar,baz"

Using TAG_ prefix for automatic tag creation

As an alternative to using the TAGS field with comma-separated values, you can use build metadata flags piecemeal with a TAG_ prefix. These will automatically be converted to tags by removing the prefix. Examples:
# Creates a tag "ENV=production"
--build_metadata=TAG_ENV=production

# Creates a tag "VERSION=v1.2.3"
--build_metadata=TAG_VERSION=v1.2.3

# Creates a tag "FEATURE" (no value)
--build_metadata=TAG_FEATURE=

# Multiple TAG_ prefixed flags can be used together
--build_metadata=TAG_ENV=staging --build_metadata=TAG_REGION=us-west-1
The TAG_ prefix method can be combined with the regular TAGS field - all tags will be merged together.
You can filter by these tags on build history pages and the trends page. Note that when filtering by tags, you will not see in-progress and disconnected builds.

Environment variable redacting

By default, all environment variables are redacted by BuildBuddy except for a whitelist of common CI-related variables which are displayed in the BuildBuddy UI.
Redacted environment variables are displayed in the BuildBuddy UI as <REDACTED>.
You can optionally allow other environment variables to be displayed using the ALLOW_ENV metadata flag. The ALLOW_ENV metadata param accepts a comma separated list of allowed environment variables and supports trailing wildcards.

Examples

Don’t redact the PATH environment variable:
build --build_metadata=ALLOW_ENV=PATH
Don’t redact the PATH environment or any environment variable beginning with BAZEL_:
build --build_metadata=ALLOW_ENV=PATH,BAZEL_*
Don’t redact any environment variables:
build --build_metadata=ALLOW_ENV=*

Build docs developers (and LLMs) love