Joeri_Damian
Joeri_Damian

Reputation: 80

Uploading files in pipeline with wildcard cURL

I am currently running a pipeline that relies on Google Cloud Platform for building a file. we want to automate the last step which is the file upload.

   - "gcloud compute ssh build-server-turnoff-when-unused --zone=europe-west4-a --command 'cd /mnt/disks/sdb/Project/ci_dev/tmp/deploy/images/project && curl -F 'image=@*.raucb' http://upload.url.com/upload'"

Now the issue is that it looks that curl -F doesn't accept wildcards, is it possible to get this done?

Upvotes: 1

Views: 1286

Answers (1)

Vi Pau
Vi Pau

Reputation: 347

Note that your command has two sets of ' ' one inside another without backspaces

In any case,

gcloud compute ssh build-server-turnoff-when-unused --zone=europe-west4-a --command "bash -c 'cd /mnt/disks/sdb/Project/ci_dev/tmp/deploy/images/project && for fileimg in *.raucb; do curl -F image="\${fileimg}" http://upload.url.com/upload ; done '"

Notes:

  • I use "bash -c" to pass to --command so it only spawns a single process remotely (avoid issues with environment)
  • cd && instead of cd ; so that if cd fails, the for does not run
  • double " inside single ' inside double " to avoid excess escaping (alternate quotes trick)
  • file extension not needed in foreach cycle as with for fileimg in *.raucb the var $fileimg will contain full filename
  • had to quote the $ for the variable as \$ or it gets interpreted by parent shell

Upvotes: 1

Related Questions