How to Run a Multi-Line Inline Script in GitHub Actions
A YAML pipe block (run: |) lets one step contain many shell lines that share the same shell process.
Use the | block scalar after run: to write several commands. They all execute in one shell invocation, so variables set on one line are visible on the next.
Steps
- Write
run: |then indent the command lines beneath it. - Keep every line at the same indent so YAML preserves them.
- Remember state persists across lines in a single step, but not across steps.
Workflow
.github/workflows/ci.yml
steps:
- run: |
echo "Preparing build"
VERSION=$(cat VERSION)
echo "Building version $VERSION"
make build VERSION="$VERSION"Gotchas
- GitHub bash runs each step with
set -eo pipefail, so a failing line aborts the step. - A variable set in one step is gone in the next; persist it via
$GITHUB_ENVif later steps need it.
Related guides
How to Run a Shell Script From the Repo in GitHub ActionsRun a committed shell script in GitHub Actions by checking out the repo, making the file executable, and invo…
How to Use set -euo pipefail in GitHub Actions ScriptsMake GitHub Actions bash scripts fail loudly by starting them with set -euo pipefail, so unset variables and…