# BuildSpec

BuildSpec for CodeBuild projects.

- Source: [`aws-codebuild/lib/build-spec.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-codebuild/lib/build-spec.ts#L12)
- Type last changed: v2.67.0 · 2 Mar 2023

## Example

```ts
import * as codebuild from 'aws-cdk-lib/aws-codebuild';

const codebuildProject = new codebuild.Project(this, 'Project', {
  projectName: 'MyTestProject',
  buildSpec: codebuild.BuildSpec.fromObject({
    version: '0.2',
    phases: {
      build: {
        commands: [
          'echo "Hello, CodeBuild!"',
        ],
      },
    },
  }),
});

const task = new tasks.CodeBuildStartBuild(this, 'Task', {
  project: codebuildProject,
  integrationPattern: sfn.IntegrationPattern.RUN_JOB,
  environmentVariablesOverride: {
    ZONE: {
      type: codebuild.BuildEnvironmentVariableType.PLAINTEXT,
      value: sfn.JsonPath.stringAt('$.envVariables.zone'),
    },
  },
});
```

## Initializer

```ts
new BuildSpec()
```

## Properties

- `isImmediate`: boolean (required) — Whether the buildspec is directly available or deferred until build-time.

## Methods

- `fromAsset(path: string): BuildSpec // chainable` (static) — Use the contents of a local file as the build spec string.

  Use this if you have a local .yml or .json file that you want to use as the buildspec

- `fromObject(value: { [key: string]: any }): BuildSpec // chainable` (static)

- `fromObjectToYaml(value: { [key: string]: any }): BuildSpec // chainable` (static) — Create a buildspec from an object that will be rendered as YAML in the resulting CloudFormation template.

  **Parameters**

  - `value` — the object containing the buildspec that will be rendered as YAML.

- `fromSourceFilename(filename: string): BuildSpec // chainable` (static) — Use a file from the source as buildspec.

  Use this if you want to use a file different from 'buildspec.yml'`

- `toBuildSpec(scope?: Construct): string` — Render the represented BuildSpec.
