0
votes

When creating a codebuild project with a codecommit source (as shown here: https://docs.aws.amazon.com/cdk/api/latest/docs/aws-codebuild-readme.html#codecommitsource), how can I set the SourceVersion for the codecommit repository?

I can specify the source version manually in console, and cloudformation supports it (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codebuild-project.html#cfn-codebuild-project-sourceversion), but appears to be no option to set this through CDK in the default codebuild project constructor.

2
I tried to look up the docs but couldn't figure out tbh. Can you also try posting your question on gitter.im/awslabs/aws-cdk which seems to be an active community.shariqmaws
I've just done so, thanksjacques

2 Answers

0
votes

You can set the SourceVersion with default node.childDefaultChild. That is a reference for CloudFormation template or CfnProject. For example to reference master-branch:

const projectCnf = project.node.defaultChild as CfnProject;
projectCnf.sourceVersion = 'refs/heads/master';

More details here: https://docs.aws.amazon.com/cdk/latest/guide/cfn_layer.html

0
votes

Try branchOrRef as documented here

  const codeBuildProject = new codeBuild.Project(
    this,
    "appWebsiteCodeBuild",
    {
      projectName: "app-website-code-build",
      source: codeBuild.Source.codeCommit({
        repository: options.repository,
        branchOrRef: "refs/heads/master",
      }),
    },
  );