Skip to content
Latchkey

gcloud storage cp: Upload Artifacts to GCS in CI

Copy files between the local filesystem and Cloud Storage buckets.

gcloud storage cp is the modern replacement for gsutil cp. In CI it uploads build artifacts, downloads fixtures, or syncs static sites. It supports recursive copies and parallel transfers for large trees.

Common flags

  • -r - copy directories recursively
  • -n - no-clobber, skip existing destination objects
  • --gzip-in-flight=js,css - compress matching extensions during upload
  • gs://BUCKET/PATH - Cloud Storage destination or source

Example in CI

Upload a build directory to a bucket prefix.

shell
gcloud storage cp -r ./dist gs://my-artifacts/builds/${GITHUB_SHA}/

Common errors in CI

  • storage.objects.create access ... denied - SA missing roles/storage.objectAdmin on the bucket
  • The specified bucket does not exist - wrong bucket name or wrong project
  • CommandException: No URLs matched - source glob did not match any local files

Key takeaways

  • Copies files to and from GCS; the successor to gsutil cp.
  • Use -r for directories and -n to avoid overwriting existing objects.
  • Most failures are missing storage IAM roles or a wrong bucket name.

Related guides

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