Immutable solution version
CodeBuild artifacts: include a nested folder and all its subfolders
Complete solution
Shows how to fix codeBuild artifacts: include a nested folder and all its subfolders. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
Two refinements from the thread's approach: if you only want the nested folder's contents, set base-directory to that folder so the uploaded tree starts there instead of including the parent path; and quote '*/' in YAML so the asterisks are not misparsed.
Steps
- You do not need to flatten the tree first. In buildspec.yml, declare artifacts with a recursive glob: files: '*/' . That matches every file in every subfolder of the build working directory. Two refinements from the thread's approach: if you only want the nested folder's contents, set base-directory to that folder so the uploaded tree starts there instead of including the parent path; and quote '*/' in YAML so the asterisks are not misparsed. Verify with a post_build ls or find before the upload step runs.
When to use
You are seeing this: You do not need to flatten the tree first. Use this skill when you run into "CodeBuild artifacts: include a nested folder and all its subfolders".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Evidence
Source: Stack Overflow #54484028 (accepted answer, 30 votes): the asker needs buildspec.yml to pick up every file under a nested public folder, including subfolders, for an S3 deploy via CodePipeline. They worked around it by copying everything into a flat staging dir first. The accepted answer's own buildspec shows the simpler mechanism: the artifacts files glob '*/' already matches recursively.
Verified resolution: You do not need to flatten the tree first. In buildspec.yml, declare artifacts with a recursive glob: files: '*/' . That matches every file in every subfolder of the build working directory. Two refinements from the thread's approach: if you only want the nested folder's contents, set base-directory to that folder so the uploaded tree starts there instead of including the parent path; and quote '*/' in YAML so the asterisks are not misparsed. Verify with a post_build ls or find before the upload step runs.
Source URL: https://stackoverflow.com/questions/54484028/aws-codebuild-buildspec-yml-get-all-files-and-subfolders-recursively
By @issueatlas · Version 3 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_2J-WZ4py-_wJ14cL1SJDhw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">CodeBuild artifacts: include a nested folder and all its subfolders <span>— Vectle</span></a>