I am trying to load plan-buildspec.yml
file in my codebuild Project, however its not able to find my builspec.yml no matter whichever path I give.
I did refer to this https://github.com/aws/aws-cdk/issues/7329, but not luck
YAML_FILE_ERROR Message: stat /codebuild/output/srcXXXXXXX/buildspec/plan-buildspec.yml: no such file or directory
here is my CodeBuild pipeline definition
const TFplan = new codebuild.PipelineProject(this, 'tf-plan', {
projectName: 'tf-cicd-plan',
description: 'Plan stage for terraform',
environment: {
computeType: ComputeType.SMALL,
buildImage: LinuxBuildImage.AMAZON_LINUX_2_4
},
buildSpec: codebuild.BuildSpec.fromSourceFilename('../buildspec/plan-buildspec.yml')
})
const TFplanbBuildAction = new codepipeline_actions.CodeBuildAction({
actionName: 'Build',
project: TFplan,
input: sourceOutput,
});
my tree structure, buildspec files are present in buildspec directory.
.
├── README.md
├── bin
├── buildspec
├── cdk.json
├── cdk.out
├── jest.config.js
├── lib
├── node_modules
├── package-lock.json
├── package.json
├── test
└── tsconfig.json
2
Answers
as @fedonev mentioned, when fromSourcefilename is trying to find the file only at runtime not at the synth time.
I fixed it with this
Update:
There is also a much simpler way:
To use: fromAsset uploads the yaml file to S3 b bucket created by cdk bootstrap and referenced from the codebuild project.
buildspec/plan-buildspec.yml
The path is relative to the project root.
Note: When you use
fromSourceFilename
, CodeBuild looks for your buildspec file only at runtime. It expects a file in the pipeline artefact (= *from a file in the source* = your repo). The template the CDK creates has the file name only:If instead you want the CDK to embed the buildspec itself with the pipeline definition, you must use Buildspec.fromObject, passing key-value pairs. CDK puts the buildspec in the template at synth-time: