(pipeline): no matching base directory path found for cdk/cdk.out
Describe the bug
I am using CDK with CodePipeline and CodeBuild, everything works fine in Linux aws/codebuild/standard:6.0.
However, when I upgrade to aws/codebuild/standard:7.0 or Amazon Linux 2 x86_64 standard image, version 5.0, npx cdk synth does nothing, as the result I got the following errors when synthesizing from pipeline.
42 | [Container] 2023/12/29 07:11:14.079166 Running command npx cdk synth
43 |
44 | [Container] 2023/12/29 07:11:16.641555 Phase complete: BUILD State: SUCCEEDED
45 | [Container] 2023/12/29 07:11:16.641572 Phase context status code: Message:
46 | [Container] 2023/12/29 07:11:16.683183 Entering phase POST_BUILD
47 | [Container] 2023/12/29 07:11:16.684920 Phase complete: POST_BUILD State: SUCCEEDED
48 | [Container] 2023/12/29 07:11:16.684933 Phase context status code: Message:
49 | [Container] 2023/12/29 07:11:16.770308 Expanding base directory path: cdk/cdk.out
50 | [Container] 2023/12/29 07:11:16.773789 Assembling file list
51 | [Container] 2023/12/29 07:11:16.773807 Expanding cdk/cdk.out
52 | [Container] 2023/12/29 07:11:16.776932 Skipping invalid file path cdk/cdk.out
53 | [Container] 2023/12/29 07:11:16.777023 Phase complete: UPLOAD_ARTIFACTS State: FAILED
54 | [Container] 2023/12/29 07:11:16.777033 Phase context status code: CLIENT_ERROR Message: no matching base directory path found for cdk/cdk.out
Expected Behavior
cdk/cdk.out should be found
Current Behavior
cdk/cdk.out is not found
Reproduction Steps
export class CdkStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const pipeline = new CodePipeline(this, 'Pipeline', {
pipelineName: 'Pipeline',
crossAccountKeys: true,
synth: new ShellStep('Synth', {
input: xxx,
commands: ['cd cdk', 'npm ci', 'npm run build', 'npx cdk synth'],
primaryOutputDirectory: 'cdk/cdk.out'
}),
codeBuildDefaults: {
buildEnvironment: {
buildImage: LinuxBuildImage.STANDARD_7_0
}
}
})
}
}
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.117.0 (build 59d9b23)
Framework Version
No response
Node.js Version
20.10.4
OS
Linux
Language
TypeScript
Language Version
No response
Other information
No response
Yes I can reproduce this issue. It fails in STANDARD_7_0 but works in STANDARD_6_0 with exactly the same configuration.
Hi team, is there any ETA for this issue?
When I run it using a global installed version (npm i -g aws-cdk) I do get a cdk.out directory locally with the cdk synth command while with the npx cdk synth I got nothing.
The package.json version and global version match so I'm not sure why.
Changing npx cdk synth to cdk synth fixed the issue on CodePipeline too, in my case.
I recently had a version of this error myself. The fix was simple, I updated my cdk.json output path from ../../dist/packages/infra to ../../dist/packages/infra/cdk.out.
Prior to this change cdk.out referred to a JSON file in ../../dist/packages/infra.
The issue has been there for more than 2 months, is there any plan to fix it?
I ran into this issue when npx cdk synth was accidentally removed from the initial CodePipeline. I tried adding it back and even tried @vroegop suggestion of changing it to just npx synth but it would never recognize the code changes and kept throwing the error. I ended up just deleting the pipeline and creating it new :/
I would be nice to know what the proper solution for this to re-recognize the synth and resolve without deletion.
I'm confused by this issue, and it looks like we've moved most users over to STANDARD_7 in https://github.com/aws/aws-cdk/issues/26810, and it doesn't look like a huge explosion of complaints of a broken pipeline has surfaced because of that.
Is this still a problem?
I am getting this error, but it might be because of my file structure. Will update if I find a fix.
In my case I had some ShellStep commands' dir wrong up in remote so all changes I pushed where ignored since the cdk pipeline could't self-update with the changes. My solution was to do a cdk deploy with the fix from my workstation and the cdk.out dir was found.
I didn't have to use a global cdk, everything worked fine:
const cdkPipeline = new cdkpipeline.CodePipeline(
this,
"SharedCdkPipeline",
{
codePipeline,
synth: new cdkpipeline.ShellStep("Synth", {
input: cdkpipeline.CodePipelineSource.connection(
`${repository.owner}/${repository.name}`,
repository.branch,
{
connectionArn: repository.connectionArn,
actionName,
},
),
installCommands: [
"npm i -g corepack@latest",
"corepack enable",
"pnpm i",
],
commands: [
"pnpm --filter '@coddi/shared...' build", // <-- my error was a typo in the filter
"pnpm --filter '@coddi/shared' cdk synth",
],
primaryOutputDirectory: "infra/cdk.out",
}),
synthCodeBuildDefaults: {
partialBuildSpec: codebuild.BuildSpec.fromObject({
version: "0.2",
phases: {
install: {
"runtime-versions": {
nodejs: 22,
},
},
},
}),
},
selfMutation: true,
},
);
When I run it using a global installed version (
npm i -g aws-cdk) I do get acdk.outdirectory locally with thecdk synthcommand while with thenpx cdk synthI got nothing. Thepackage.jsonversion and global version match so I'm not sure why.Changing
npx cdk synthtocdk synthfixed the issue on CodePipeline too, in my case.
Although the issue is still there, I have finally solved it by using the global CDK. This is a valuable clue, AWS team please debug it ASAP.