Skip to content

Instantly share code, notes, and snippets.

@u2mejc
Created October 28, 2024 21:07
Show Gist options
  • Save u2mejc/9f52de7f3a830170c962634bcb6fe2ec to your computer and use it in GitHub Desktop.
Save u2mejc/9f52de7f3a830170c962634bcb6fe2ec to your computer and use it in GitHub Desktop.
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 don't work on different lines in CodeBuild.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment