Buildkite Pre-Command Environment Example
This repository is an example Buildkite pipeline that demonstrates how environment variables can be set through a repository hook.
See the full Getting Started Guide for step-by-step instructions on how to get this running.
How it works
This pipeline demonstrates how to use the pre-command hook to dynamically set environment variables at runtime for each job.
In this example:
.buildkite/hooks/pre-commandsets aGIT_SHORT_HASHvariablecheck_environment_var.shprints that variable- The hook runs once per job and is scoped to that job context only
This can be helpful for injecting metadata into your builds without hardcoding values into your pipeline configuration.
Notes
- Environment vars are scoped to a job context and cleaned up to prevent polluting other job contexts.
- The environment var exported by
pre-commandin this example is calculated every time a job in this pipeline is run. - If the environment variable was expensive to calculate or non-deterministic, you might want to consider only calculating it during the pipeline upload step and setting the
envinside the pipeline.yml
License
See LICENSE (MIT)



