Safe CI inputs and interpolation
Workflow fields such as pull request titles, branch names and commit messages may be controlled by people outside the trusted build team. The CI template engine and Bash parser are different layers. Substituting a field into a shell script before parsing can change the script's grammar, even when the template appears quoted. Do not place untrusted template expressions directly into executable source. Pass a value using the provider's environment-variable mechanism, then use quoted shell expansion and a fixed command. Treat environment values as untrusted too.
Validate according to the destination
A branch label for display may allow spaces and punctuation; a release channel used as a directory selector should have a narrow allowlist. Do not use eval or generate shell source from such values. A fixed printf format avoids format interpretation. Do not send raw untrusted text into provider-specific logging command channels; the lab reports lengths or fixed labels instead. Keep secrets out of command traces and unnecessary logs. Masking is a backup, not a guarantee: derived or encoded values can escape filters.
Give jobs only necessary permissions. Do not run untrusted changes with deployment credentials or privileged runners. Pin and review third-party actions. The examples use harmless synthetic input, no provider tokens or actual workflows. The optional notes describe passing a GitHub expression through an environment field and consuming GitLab variables as data. The channel function checks argument count before reading $1, and its rejection drill verifies status 2. Passing text through an environment variable avoids this template-to-code boundary only when the script treats that text as data.
Practical examples
Run each example as a separate script in a fresh noninteractive Bash 5.2 process and empty practice directory. Tests use C locale; do not enter expected output as code. Git, GNU tar, gzip and coreutils are external dependencies for the relevant examples. Do not run these in an existing repository or CI workspace.
Pass a label as data
LABEL='review 100% ready' /bin/bash --noprofile --norc -c ' set -- "$LABEL" printf "arguments=%s length=%s\n" "$#" "${#1}"' Expected stdout:
arguments=1 length=17The child gets one environment value; no raw label is printed into a CI log.
Allowlist release channels
channel() { [[ $# == 1 ]] || return 2 case $1 in preview|stable) printf 'accepted\n' ;; *) return 2 ;; esac}channel preview || exit 1if channel 'other channel'; then exit 1; else rc=$? [[ $rc == 2 ]] || exit 1 printf 'rejected=%s\n' "$rc"fiExpected stdout:
acceptedrejected=2Only fixed supported values can select a release path.
Avoid printing synthetic credentials
set +xtoken=DEMO_ONLY_TOKENif [[ -n $token ]]; then printf 'credential configured\n'fiunset token[[ ! -v token ]]Expected stdout:
credential configuredOnly a fixed status is emitted. Unset is not secure memory erasure.
Common mistakes
Quoting the template expression itself is not enough; shell quoting applies only after the script has been generated.
Practice
Use a synthetic label with spaces and percent signs; verify it remains one argument. Reject an unsupported channel and show that no release action runs.
Next: Artifacts and release verification