Runtime context built from Buildkite environment variables.
Captures the CI environment (branch, commit, PR info) into a struct that other modules use for decision-making.
Fields
:branch— current branch name (BUILDKITE_BRANCH):default_branch— pipeline default branch (BUILDKITE_PIPELINE_DEFAULT_BRANCH, defaults to"main"):commit— current commit SHA (BUILDKITE_COMMIT):message— commit message (BUILDKITE_MESSAGE):pull_request_base_branch— PR base branch, if any (BUILDKITE_PULL_REQUEST_BASE_BRANCH):ci_target— explicit targeting via env var (CI_TARGET):is_default_branch—truewhen:branchequals:default_branch
Example
ctx = Pipette.Context.from_env(%{
"BUILDKITE_BRANCH" => "feature/login",
"BUILDKITE_PIPELINE_DEFAULT_BRANCH" => "main",
"BUILDKITE_COMMIT" => "abc123",
"BUILDKITE_MESSAGE" => "[ci:api] Fix login bug",
"BUILDKITE_PULL_REQUEST_BASE_BRANCH" => "main"
})
ctx.branch #=> "feature/login"
ctx.is_default_branch #=> false
Summary
Functions
Build a context from a map of environment variables.
Build a context from the current system environment.
Types
Functions
Build a context from a map of environment variables.
This is the primary constructor. In tests, pass a map with the Buildkite environment variables you want to simulate.
Examples
ctx = Pipette.Context.from_env(%{
"BUILDKITE_BRANCH" => "feature/login",
"BUILDKITE_PIPELINE_DEFAULT_BRANCH" => "main",
"BUILDKITE_COMMIT" => "abc123",
"BUILDKITE_MESSAGE" => "Fix login"
})
ctx.branch #=> "feature/login"
@spec from_system_env() :: t()
Build a context from the current system environment.
Convenience wrapper that calls from_env(System.get_env()).
Used in production when running inside a Buildkite agent.