Getting started with Buildkite + CUE
The CUE Central Registry provides a well-known location for well-known schemas, including those for YAML pipeline files used by Buildkite pipelines. This guide shows you how to get started defining your Buildkite pipelines in CUE using a curated module from the schema library.
Initialize your local CUE module
CUE that uses schemas and modules from the Central Registry needs to exist within its own CUE module.
$ cue mod init cue.exampleYou can choose any module name you like, and change it later. It makes sense for your CUE module to exist at the root of a git repository that’s configured to trigger Buildkite. The commands in this guide work in any setup.
Create a pipeline
Declare a Buildkite pipeline in CUE. This one is based on a Buildkite example:
package cicd
import "cue.dev/x/buildkite"
pipelines: example: buildkite.#Pipeline & {
steps: [{
label: ":hammer: Example Script"
command: """
echo "--- :package: Build job checkout directory"
pwd
ls -la
echo "--- :evergreen_tree: Build job environment"
env
echo "+++ :hammer: Example tests"
echo "Congratulations! You've successfully run your first build on Buildkite! 👍"
"""
}]
}
In later guides we’ll add more entries to the pipelines struct.
The import at the top references the appropriate curated module for the pipeline.
Its path is currently temporary, but only while its proper location is being decided.
The temporary path isn’t a problem: once a schema is published to the Central Registry, it is always available at that location.
When versions are published at the curated module’s final location, use the cue refactor imports command to update your CUE.
Tidy your local CUE module
$ cue mod tidyTidying a module is part of using curated modules from the
Central Registry.
Always use
cue mod tidy
when you use a curated module for the first time.
If you see an error message mentioning “too many requests” then login to the Central Registry and re-run this command. The Central Registry allows more requests from authenticated users.
Validate your pipeline
$ cue vet -cBecause cue vet doesn’t display any errors, you know that the curated schema has validated your pipeline.
Export your pipeline as YAML
Before exporting your pipeline you’ll need to create a directory to hold it, as expected by Buildkite:
$ mkdir .buildkite
$ cue export --outfile .buildkite/pipeline.yml -e pipelines.exampleIf you chose to export the pipelines.example shown above,
your validated YAML pipeline will look like this:
steps:
- label: ':hammer: Example Script'
command: "echo \"--- :package: Build job checkout directory\"\npwd\nls -la\necho \"--- :evergreen_tree: Build job environment\"\nenv\necho \"+++ :hammer: Example tests\"\necho \"Congratulations! You've successfully run your first build on Buildkite! \U0001F44D\""Run your pipeline
The cue.mod and .buildkite directories need to be stored in your git
repository, along with your pipeline.cue file.
After recording them in a commit you can push your branch to your git remote
and trigger the pipeline.
Whenever you update your CUE pipeline, re-run the cue export command shown above. Then use git to record any changes to these files and directories.