Skip to content

Instantly share code, notes, and snippets.

View u2mejc's full-sized avatar

Justin Clark u2mejc

View GitHub Profile
@u2mejc
u2mejc / shellcheck-buildspec.md
Created October 28, 2024 21:07
shellcheck for AWS's CodeBuild buildspec.yaml

shellcheck is an invaluable tool for validating shell (typically Bash) scripts. When working with a codified CI environment like AWS's CodeBuild, the shell script is defined inside a YAML list (YAML sequence). You can still run shellcheck, by parsing the YAML file with a tool like yq and piping the output to shellcheck:

yq '.phases.build.commands[]' < buildspec.yaml | shellcheck -

Note: shellcheck assumes that everything is a single file, which would execute consecutively in the same shell, but CodeBuild executes each string (line) in a new shell, copying exports only. So things like set