Skip to content
Latchkey

curl Command Reference for CI Scripts

curl moves bytes between a runner and a URL, scriptably and without a browser.

curl is the default HTTP client in pipelines. The trick in CI is making it fail loudly and retry sensibly instead of silently writing an error page to a file.

Common flags/usage

  • -f / --fail: exit non-zero on HTTP >= 400 instead of writing the error body
  • -sS: silent but still show errors (combine -s with -S)
  • -L / --location: follow redirects
  • -o FILE / -O: write to a named file / use the remote filename
  • --retry N --retry-delay S --retry-all-errors: retry transient failures

Example

shell
curl -fsSL -o app.tar.gz \
  --retry 5 --retry-delay 2 --retry-all-errors \
  "https://example.com/releases/${VERSION}/app.tar.gz"
curl -fsS -H "Authorization: Bearer ${TOKEN}" https://api.example.com/v1/status

In CI

Always pass -f so an HTTP 500 does not get piped into bash or saved as a "valid" archive, and -sS so silent mode still surfaces the real error. Key exit codes: 6 = DNS failure, 7 = connection refused, 22 = HTTP error with -f, 28 = timeout. Add --retry for flaky networks.

Key takeaways

  • Use -fsSL as the default flag set: fail on HTTP errors, stay quiet, show errors, follow redirects.
  • Pipe untrusted downloads through -f so error pages never reach bash or a file.
  • --retry with --retry-all-errors hardens downloads against transient CI network blips.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →