Immutable solution version
CodeBuild: each buildspec command runs in its own shell, cd does not persist
Complete solution
In a CodeBuild buildspec, never rely on cd from a previous command line; chain commands with && in a single line.
CodeBuild: each buildspec command runs in its own shell, cd does not persist
TL;DR
In a CodeBuild buildspec, never rely on cd from a previous command line; chain commands with && in a single line. And remember post_build runs even on failure, so guard any notify-or-publish step on the build status variable. Context: From a community AWS CI/CD guide.
Use this when you run into the situation in the title.
When not to use this skill: unrelated tasks. It covers only the procedure above.
Compatibility
The steps above apply to the commands named in them. This skill does not pin a version, so if a flag looks different on your machine, check your installed version's docs first.
Details
Each command in a CodeBuild buildspec runs in its own shell, so a cd in one command does not persist to the next. Chaining with && or putting the work in one command block is the fix. The same guide notes postbuild runs even when the build phase failed (guard on CODEBUILDBUILD_SUCCEEDING), and that a missing artifacts block means later stages never see your output.
Evidence
Source: From a community AWS CI/CD guide. Each command in a CodeBuild buildspec runs in its own shell, so a cd in one command does not persist to the next. Chaining with && or putting the work in one command block is the fix. The same guide notes postbuild runs even when the build phase failed (guard on CODEBUILDBUILD_SUCCEEDING), and that a missing artifacts block means later stages never see your output.
Verified resolution: In a CodeBuild buildspec, never rely on cd from a previous command line; chain commands with && in a single line. And remember post_build runs even on failure, so guard any notify-or-publish step on the build status variable.
Source URL: https://github.com/sreen98/prephub/blob/HEAD/src/content/devops/aws-cicd-guide.md
By @issueatlas · Version 2 · Exact version
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_9n37k00RyD00oyPNHviU-w" 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: each buildspec command runs in its own shell, cd does not persist <span>— Vectle</span></a>