# CodeBuildOptions

Options for customizing a single CodeBuild project.

- Source: [`pipelines/lib/codepipeline/codepipeline.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline.ts#L308)
- Type last changed: v2.93.0 · 23 Aug 2023

## Example

TypeScript:

```ts
declare const source: pipelines.IFileSetProducer; // the repository source
declare const synthCommands: string[]; // Commands to synthesize your app
declare const installCommands: string[]; // Commands to install your toolchain

const pipeline = new pipelines.CodePipeline(this, 'Pipeline', {
  // Standard CodePipeline properties...
  synth: new pipelines.ShellStep('Synth', {
    input: source,
    commands: synthCommands,
  }),

  // Configure CodeBuild to use a drop-in Docker replacement.
  codeBuildDefaults: {
    partialBuildSpec: codebuild.BuildSpec.fromObject({
      phases: {
        install: {
          // Add the shell commands to install your drop-in Docker
          // replacement to the CodeBuild enviromment.
          commands: installCommands,
        },
      },
    }),
    buildEnvironment: {
      environmentVariables: {
        // Instruct the AWS CDK to use `drop-in-replacement` instead of
        // `docker` when building / publishing docker images.
        // e.g., `drop-in-replacement build . -f path/to/Dockerfile`
        CDK_DOCKER: { value: 'drop-in-replacement' },
      },
    },
  },
});
```

Python:

```python
# source: pipelines.IFileSetProducer # the repository source
# synth_commands: List[str] # Commands to synthesize your app
# install_commands: List[str]
# Commands to install your toolchain

pipeline = pipelines.CodePipeline(self, "Pipeline",
    # Standard CodePipeline properties...
    synth=pipelines.ShellStep("Synth",
        input=source,
        commands=synth_commands
    ),

    # Configure CodeBuild to use a drop-in Docker replacement.
    code_build_defaults=pipelines.CodeBuildOptions(
        partial_build_spec=codebuild.BuildSpec.from_object({
            "phases": {
                "install": {
                    # Add the shell commands to install your drop-in Docker
                    # replacement to the CodeBuild enviromment.
                    "commands": install_commands
                }
            }
        }),
        build_environment=codebuild.BuildEnvironment(
            environment_variables={
                # Instruct the AWS CDK to use `drop-in-replacement` instead of
                # `docker` when building / publishing docker images.
                # e.g., `drop-in-replacement build . -f path/to/Dockerfile`
                "CDK_DOCKER": codebuild.BuildEnvironmentVariable(value="drop-in-replacement")
            }
        )
    )
)
```

Java:

```java
IFileSetProducer source; // the repository source
String[] synthCommands; // Commands to synthesize your app
String[] installCommands;
// Commands to install your toolchain

CodePipeline pipeline = CodePipeline.Builder.create(this, "Pipeline")
        // Standard CodePipeline properties...
        .synth(ShellStep.Builder.create("Synth")
                .input(source)
                .commands(synthCommands)
                .build())

        // Configure CodeBuild to use a drop-in Docker replacement.
        .codeBuildDefaults(CodeBuildOptions.builder()
                .partialBuildSpec(BuildSpec.fromObject(Map.of(
                        "phases", Map.of(
                                "install", Map.of(
                                        // Add the shell commands to install your drop-in Docker
                                        // replacement to the CodeBuild enviromment.
                                        "commands", installCommands)))))
                .buildEnvironment(BuildEnvironment.builder()
                        .environmentVariables(Map.of(
                                // Instruct the AWS CDK to use `drop-in-replacement` instead of
                                // `docker` when building / publishing docker images.
                                // e.g., `drop-in-replacement build . -f path/to/Dockerfile`
                                "CDK_DOCKER", BuildEnvironmentVariable.builder().value("drop-in-replacement").build()))
                        .build())
                .build())
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
IFileSetProducer source; // the repository source
string[] synthCommands; // Commands to synthesize your app
string[] installCommands;
// Commands to install your toolchain

var pipeline = new CodePipeline(this, "Pipeline", new CodePipelineProps {
    // Standard CodePipeline properties...
    Synth = new ShellStep("Synth", new ShellStepProps {
        Input = source,
        Commands = synthCommands
    }),

    // Configure CodeBuild to use a drop-in Docker replacement.
    CodeBuildDefaults = new CodeBuildOptions {
        PartialBuildSpec = BuildSpec.FromObject(new Dictionary<string, object> {
            { "phases", new Dictionary<string, IDictionary<string, string[]>> {
                { "install", new Struct {
                    // Add the shell commands to install your drop-in Docker
                    // replacement to the CodeBuild enviromment.
                    Commands = installCommands
                } }
            } }
        }),
        BuildEnvironment = new BuildEnvironment {
            EnvironmentVariables = new Dictionary<string, BuildEnvironmentVariable> {
                // Instruct the AWS CDK to use `drop-in-replacement` instead of
                // `docker` when building / publishing docker images.
                // e.g., `drop-in-replacement build . -f path/to/Dockerfile`
                { "CDK_DOCKER", new BuildEnvironmentVariable { Value = "drop-in-replacement" } }
            }
        }
    }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var source IFileSetProducer // the repository source
var synthCommands []*string // Commands to synthesize your app
var installCommands []*string
// Commands to install your toolchain

pipeline := pipelines.NewCodePipeline(this, jsii.String("Pipeline"), &CodePipelineProps{
	// Standard CodePipeline properties...
	Synth: pipelines.NewShellStep(jsii.String("Synth"), &ShellStepProps{
		Input: source,
		Commands: synthCommands,
	}),

	// Configure CodeBuild to use a drop-in Docker replacement.
	CodeBuildDefaults: &CodeBuildOptions{
		PartialBuildSpec: codebuild.BuildSpec_FromObject(map[string]interface{}{
			"phases": map[string]map[string][]*string{
				"install": map[string][]*string{
					// Add the shell commands to install your drop-in Docker
					// replacement to the CodeBuild enviromment.
					"commands": installCommands,
				},
			},
		}),
		BuildEnvironment: &BuildEnvironment{
			EnvironmentVariables: map[string]BuildEnvironmentVariable{
				// Instruct the AWS CDK to use `drop-in-replacement` instead of
				// `docker` when building / publishing docker images.
				// e.g., `drop-in-replacement build . -f path/to/Dockerfile`
				"CDK_DOCKER": &BuildEnvironmentVariable{
					"value": jsii.String("drop-in-replacement"),
				},
			},
		},
	},
})
```

## Properties

- `buildEnvironment`: [BuildEnvironment](/cdk/api/v2/docs/aws-cdk-lib.aws_codebuild.BuildEnvironment.html) — Partial build environment, will be combined with other build environments that apply.

  **Default:** Non-privileged build, SMALL instance, LinuxBuildImage.STANDARD_7_0

- `cache`: [Cache](/cdk/api/v2/docs/aws-cdk-lib.aws_codebuild.Cache.html) — Caching strategy to use.

  **Default:** No cache

- `fileSystemLocations`: [IFileSystemLocation](/cdk/api/v2/docs/aws-cdk-lib.aws_codebuild.IFileSystemLocation.html)[] — ProjectFileSystemLocation objects for CodeBuild build projects.

  **Default:** no file system locations

  A ProjectFileSystemLocation object specifies the identifier, location, mountOptions, mountPoint,
  and type of a file system created using Amazon Elastic File System.
  Requires a vpc to be set and privileged to be set to true.

- `logging`: [LoggingOptions](/cdk/api/v2/docs/aws-cdk-lib.aws_codebuild.LoggingOptions.html) — Information about logs for CodeBuild projects.

  **Default:** no log configuration is set

  A CodeBuild project can create logs in Amazon CloudWatch Logs, an S3 bucket, or both.

- `partialBuildSpec`: [BuildSpec](/cdk/api/v2/docs/aws-cdk-lib.aws_codebuild.BuildSpec.html) — Partial buildspec, will be combined with other buildspecs that apply.

  **Default:** No initial BuildSpec

  The BuildSpec must be available inline--it cannot reference a file
  on disk.

- `rolePolicy`: [PolicyStatement](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.PolicyStatement.html)[] — Policy statements to add to role.

  **Default:** No policy statements added to CodeBuild Project Role

- `securityGroups`: [ISecurityGroup](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISecurityGroup.html)[] — Which security group(s) to associate with the project network interfaces.

  **Default:** Security group will be automatically created.

  Only used if 'vpc' is supplied.

- `subnetSelection`: [SubnetSelection](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.SubnetSelection.html) — Which subnets to use.

  **Default:** All private subnets.

  Only used if 'vpc' is supplied.

- `timeout`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) = Duration.hours(1) — The number of minutes after which AWS CodeBuild stops the build if it's not complete.

  For valid values, see the timeoutInMinutes field in the AWS
  CodeBuild User Guide.

- `vpc`: [IVpc](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IVpc.html) — The VPC where to create the CodeBuild network interfaces in.

  **Default:** No VPC
