Search code examples
google-cloud-build

Can Google Cloud Build recurse through directories of artifacts?


My workspace looks like this:

|
|--> web-app
     |
     |--> src
     |--> build
          |
          |--> fonts
          |--> static

My cloudbuild.json looks like this:

{
    "steps" : [
    {
...
    },
    ],
    "artifacts": {
        "objects": {
            "location": "gs://my_bucket/",
            "paths": [
                "web-app/build/**"
            ]
        }
    }
}

What I'm hoping for is that Google Cloud Build will recurse through the contents of the build/ folder and copy the files & directories to my storage bucket. Instead it only copies the files that are rooted in the build/ directory, ignores the directories and gives a warning about using the -r option of gsutil cp.

Here is the build output:

...
Artifacts will be uploaded to gs://my_bucket using gsutil cp
web-app/build/**: Uploading path....
Omitting directory "file://web-app/build/fonts". (Did you mean to do cp -r?)
Omitting directory "file://web-app/build/static". (Did you mean to do cp -r?)
Copying file://web-app/build/index.html [Content-Type=text/html]...
Copying file://web-app/build/asset-manifest.json [Content-Type=application/json]...
Copying file://web-app/build/favicon.ico [Content-Type=image/vnd.microsoft.icon]...
Copying file://web-app/build/manifest.json [Content-Type=application/json]...   
Copying file://web-app/build/service-worker.js [Content-Type=application/javascript]...
/ [5/5 files][ 28.4 KiB/ 28.4 KiB] 100% Done                                    
Operation completed over 5 objects/28.4 KiB.                                     
web-app/build/**: 5 matching files uploaded
5 total artifacts uploaded to gs://my_bucket/
Uploading manifest artifacts-d4a2b3e4-97ba-4eb0-b226-e0c914ac4f61.json
Artifact manifest located at gs://my_bucket/artifacts-d4a2b3e4-97ba-4eb0-b226-e0c914ac4f61.json
DONE

The documentation https://cloud.google.com/storage/docs/gsutil/addlhelp/WildcardNames#directory-by-directory-vs-recursive-wildcards suggests that this shouldn't be the case.

I guess I could use the gsutil cloud builder but my suspicion is that I don't need to and that I'm doing something wrong here.


Solution

  • There's currently (2018-11) no way to copy an artifacts directory recursively one-to-one. Your best bet is to use a gsutil step in your cloudbuild.yaml file (as you mentioned already), similar to:

    steps:
    - ....
    - name: 'gcr.io/cloud-builders/gsutil'
      args: ['-m', 'cp', '-r', 'web-app/build*', 'gs://my_bucket/$BUILD_ID']