Skip to content
BETAGuardrails are in beta. The library, the configuration format and the CLI command can still change.

Guardrails / Collectors

CI environment

Where the build is running: which CI provider, whether the runner is hosted or self hosted, what triggered it, and whether federated credentials are available to it.

Facts keyenv
Versionv1
Scriptenv.py
Timeout30 seconds

Inputs

InputDescriptionDefaultEnvironment
envFileRead the environment from this KEY=VALUE file instead of the process environment. Meant for testing a guardrail against a runner you are not on.``GUARDRAIL_INPUT_ENVFILE

A guardrail that declares an input of the same name passes it through, so the guardrail's configuration in buildnote.json is what decides these values.

A guardrail asks for these facts by name, and reads them back the same way:

json
{
  "collect": ["env"]
}
python
env = guardrail.facts("env")

Facts

The document env collects. A path carrying [] is an entry of the list before it, and one carrying [path] is a key of the object before it.

FactMeaning
ciWhether the build is running on a CI runner at all rather than on somebody's workstation.
providerCI provider recognised from its own variables: github, gitlab, jenkins, azure, circle, buildkite, teamcity, bitbucket, drone, travis, or local when none of them.
hostedWhether the runner is the provider's own hosted fleet. false for a self hosted runner, null when the provider does not say.
triggerWhat started the build, as the provider names it, or null.
pullRequestWhether the build is for a pull or merge request.
forkWhether that request came from a fork, null when the provider does not say. A fork build is the one that must run without secrets.
runner.osOperating system the runner reports, or null.
runner.archArchitecture the runner reports, or null.
runner.nameName the runner reports, or null.
oidcWhether a federated identity token is available to this job, so a pipeline can reach a cloud without a long lived key.
variablesNames of the CI variables that were set. Names only, never values: the facts are attached to the run event and a value can be a credential.

A collector that cannot finish prints what it had along with an incomplete key saying why, so the facts below the point it stopped are absent. A check that cares reads incomplete before the rest.

Example facts

The example facts collected by env collector:

json
{
  "provider": "github",
  "ci": true,
  "hosted": true,
  "trigger": "pull_request",
  "pullRequest": true,
  "fork": null,
  "runner": {
    "os": "Linux",
    "arch": "X64",
    "name": "GitHub Actions 4"
  },
  "oidc": true,
  "variables": [
    "CI",
    "GITHUB_ACTIONS",
    "GITHUB_BASE_REF",
    "GITHUB_EVENT_NAME",
    "GITHUB_HEAD_REF",
    "GITHUB_RUN_ID",
    "GITHUB_WORKFLOW",
    "RUNNER_ARCH",
    "RUNNER_ENVIRONMENT",
    "RUNNER_NAME",
    "RUNNER_OS"
  ]
}

Collected for

GuardrailCategoryInputs
build/runs-on-hosted-cibuildnone

All collectors

Buildnote Limited
Registered in England and Wales, Reg: 16140412