Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codebuild not able to find buildspec.yml file using fromSourceFilename method #23324

Closed
jatinmehrotra opened this issue Dec 13, 2022 · 6 comments
Assignees
Labels
@aws-cdk/aws-codebuild Related to AWS CodeBuild closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@jatinmehrotra
Copy link

Describe the bug

I am trying to use YAML commands from buildspec.yml file using codebuild.BuildSpec.fromSourceFilename but codebuild is unable to find this file,, when I trying to run build job.

Expected Behavior

It should run my commands present in the yml file.

Current Behavior

It shows error In the build logs Phase context status code: YAML_FILE_ERROR Message: stat /codebuild/output/srcxxxxxxx3/src/buildspec/plan-buildspec.yml: no such file or directory

Reproduction Steps

here is my cdk code

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,
    });

pipeline code

const pipeline = new codepipeline.Pipeline(this, 'CodePipeline', {
      pipelineName: 'jatin-ci-cd',
      crossAccountKeys: false, // not required as it wont be cross account deployment
      stages: [

        {
          stageName: 'Source',
          actions: [sourceAction]
        },

        {
          stageName: 'Plan',
          actions: [TFplanbBuildAction]
        },
        // code

My directory structure

./lib
├── pipeline-source-bucket.ts
└── pipeline-stack.ts
./buildspec
├── apply-buildspec.yml
└── plan-buildspec.yml

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.44.0 (build bf32cb1)

Framework Version

No response

Node.js Version

16.17.0

OS

macOS

Language

Typescript

Language Version

4.6.2

Other information

No response

@jatinmehrotra jatinmehrotra added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 13, 2022
@github-actions github-actions bot added the @aws-cdk/aws-codebuild Related to AWS CodeBuild label Dec 13, 2022
@jatinmehrotra
Copy link
Author

@peterwoodworth any update on this?

@peterwoodworth
Copy link
Contributor

From the CloudFormation docs:

If this value is provided, it can be either a single string containing the entire build specification, or the path to an alternate buildspec file relative to the value of the built-in environment variable CODEBUILD_SRC_DIR.

Are you sure that your codebuild project has this file defined where you're expecting it to be?

@peterwoodworth peterwoodworth added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. needs-reproduction This issue needs reproduction. and removed needs-triage This issue or PR still needs to be triaged. labels Dec 13, 2022
@jatinmehrotra
Copy link
Author

jatinmehrotra commented Dec 14, 2022

You can check my directory structure mentioned in issue, looking by that I think so its is there where it should be.

After reading you comment and the link to docs I have few questions ?

  • How to find the location of CODEBUILD_SRC_DIR. I think this is something determined by CDK at runtime, so I dont think so I have control over the location of this variable?
  • After reading this issue CodeBuild buildspec should support YAML FileAsset and project file name #1138, Is it right to presume CDK does not have support for inline YAML file anymore?
  • From the docs you mentioned, under the heading Project without a source sample, it says something like this You can configure a CodeBuild project by choosing the NO_SOURCE source type when you configure your source. When your source type is NO_SOURCE, you cannot specify a buildspec file because your project does not have a source. Instead, you must specify a YAML-formatted buildspec string in the buildspec attribute of the JSON-formatted input to the create-project CLI command. It might look like this:. CDK's codebuild.PipelineProject does not expose a way to use source. In the past I have use terraform it was fine in that

I replaced my current code with this and it worked. I got a similar response on StackOverflow too https://stackoverflow.com/a/74784379/13126651
buildSpec: codebuild.BuildSpec.fromObject(yaml.parse(fs.readFileSync('buildspec/plan-buildspec.yml', 'utf8')))

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Dec 14, 2022
@peterwoodworth
Copy link
Contributor

How to find the location of CODEBUILD_SRC_DIR

This is the directory of whatever your source is.

You can check my directory structure mentioned in issue, looking by that I think so its is there where it should be.

I was asking you to make sure that this is the case in your codebuild source directory, not your local directory. It sounds like this was the case since you got the workaround to work using your local file

@peterwoodworth peterwoodworth added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed bug This issue is a bug. needs-reproduction This issue needs reproduction. labels Dec 19, 2022
@github-actions
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Dec 22, 2022
@jakegrabowski
Copy link

seem this is still an issue as I am facing similar problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codebuild Related to AWS CodeBuild closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

4 participants