How to refer to buildspec files from CDK code?

0

I am currently building a codepipeline using AWS CDK in which I am making use of multiple codebuild projects for different codebuild actions that are part of several codepipeline stages. I have separate build specification files for each of the codebuild project under the folder - "buildspecs". This "buildspecs" resides in the root of my AWS CDK project. Now I want to refer to individual buildspec files from different pipeline source code files. For example, I want to refer to buildspecs/UnitTestsBuildSpec.yml from lib/infra/cicd/stages/unit-test-stage.ts. How can I do so? I saw different options in the documentations such as BuildSpec.fromSourceFileName, BuildSpec.fromObject, BuildSpec.fromAsset but I am confused which one to use because of lack of proper documentation around it. For now, I have used BuildSpec.fromSourceFileName but not sure whether to use relative path from the file I am in (like ../../../buildspecs/UnitTestsBuildSpec.yml) or to use absolute path from the root of the project (like buildspec/UnitTestsBuildSpec.yml). I see people using other options like fromAsset and fromObject on stackoverflow and github issues pages. Which one should I use and how? Any help would be appreciated. Thanks.

질문됨 10달 전616회 조회
2개 답변
1

You need to use BuildSpec.fromSourceFileName to specify the path of the file in the source repository. The other methods, namely fromObject and fromAsset, are intended for CDK projects where the buildspec is stored locally to the project. To keep it simple, review the following:

fromAsset - loads from a local file path of the CDK project

fromObject - loads from an object variable in memory

fromSourceFileName - specifies the filename and path in the source code repo for the yml file of your buildspec.

Hope this helps, please accept this answer if it does.

profile picture
답변함 10달 전
  • Hey Bryant, this was helpful. But I am a bit confused between fromSourceFileName and fromAsset explanation given above. Both seem the same to me. Please can you clarify it a bit?

1

The difference between fromAsset and fromSourceFileName is that fromAsset uses files locally while fromSourceFileName uses from the source code server (which is not the local git repository).

Let's assume you had a config folder off the root of your project. You could use the FromAsset method to load from this config folder.

If you have want to reference the buildspec from source code repository (on either Github, CodeCommit, or BitBucket) you would utilize the fromSourceFileName method. This source code repository is not your local development environment.

Hope this helps

profile picture
답변함 10달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠