Skip to content
v2.277.0

BuildEnvironment Struct ​

Example ​

ts
const pipeline = new pipelines.CodePipeline(this, 'Pipeline', {
  synth: new pipelines.ShellStep('Synth', {
    input: pipelines.CodePipelineSource.connection('my-org/my-app', 'main', {
      connectionArn:
        'arn:aws:codestar-connections:us-east-1:222222222222:connection/7d2469ff-514a-4e4f-9003-5ca4a43cdc41', // Created using the AWS console * });',
    }),
    commands: ['npm ci', 'npm run build', 'npx cdk synth'],
  }),

  // Turn this on because the pipeline uses Docker image assets
  dockerEnabledForSelfMutation: true,
});

pipeline.addWave('MyWave', {
  post: [
    new pipelines.CodeBuildStep('RunApproval', {
      commands: ['command-from-image'],
      buildEnvironment: {
        // The user of a Docker image asset in the pipeline requires turning on
        // 'dockerEnabledForSelfMutation'.
        buildImage: codebuild.LinuxBuildImage.fromAsset(this, 'Image', {
          directory: './docker-image',
        }),
      },
    }),
  ],
});
python
pipeline = pipelines.CodePipeline(self, "Pipeline",
    synth=pipelines.ShellStep("Synth",
        input=pipelines.CodePipelineSource.connection("my-org/my-app", "main",
            connection_arn="arn:aws:codestar-connections:us-east-1:222222222222:connection/7d2469ff-514a-4e4f-9003-5ca4a43cdc41"
        ),
        commands=["npm ci", "npm run build", "npx cdk synth"]
    ),

    # Turn this on because the pipeline uses Docker image assets
    docker_enabled_for_self_mutation=True
)

pipeline.add_wave("MyWave",
    post=[
        pipelines.CodeBuildStep("RunApproval",
            commands=["command-from-image"],
            build_environment=codebuild.BuildEnvironment(
                # The user of a Docker image asset in the pipeline requires turning on
                # 'dockerEnabledForSelfMutation'.
                build_image=codebuild.LinuxBuildImage.from_asset(self, "Image",
                    directory="./docker-image"
                )
            )
        )
    ]
)
java
CodePipeline pipeline = CodePipeline.Builder.create(this, "Pipeline")
        .synth(ShellStep.Builder.create("Synth")
                .input(CodePipelineSource.connection("my-org/my-app", "main", ConnectionSourceOptions.builder()
                        .connectionArn("arn:aws:codestar-connections:us-east-1:222222222222:connection/7d2469ff-514a-4e4f-9003-5ca4a43cdc41")
                        .build()))
                .commands(List.of("npm ci", "npm run build", "npx cdk synth"))
                .build())

        // Turn this on because the pipeline uses Docker image assets
        .dockerEnabledForSelfMutation(true)
        .build();

pipeline.addWave("MyWave", WaveOptions.builder()
        .post(List.of(
            CodeBuildStep.Builder.create("RunApproval")
                    .commands(List.of("command-from-image"))
                    .buildEnvironment(BuildEnvironment.builder()
                            // The user of a Docker image asset in the pipeline requires turning on
                            // 'dockerEnabledForSelfMutation'.
                            .buildImage(LinuxBuildImage.fromAsset(this, "Image", DockerImageAssetProps.builder()
                                    .directory("./docker-image")
                                    .build()))
                            .build())
                    .build()))
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
var pipeline = new CodePipeline(this, "Pipeline", new CodePipelineProps {
    Synth = new ShellStep("Synth", new ShellStepProps {
        Input = CodePipelineSource.Connection("my-org/my-app", "main", new ConnectionSourceOptions {
            ConnectionArn = "arn:aws:codestar-connections:us-east-1:222222222222:connection/7d2469ff-514a-4e4f-9003-5ca4a43cdc41"
        }),
        Commands = new [] { "npm ci", "npm run build", "npx cdk synth" }
    }),

    // Turn this on because the pipeline uses Docker image assets
    DockerEnabledForSelfMutation = true
});

pipeline.AddWave("MyWave", new WaveOptions {
    Post = new [] {
        new CodeBuildStep("RunApproval", new CodeBuildStepProps {
            Commands = new [] { "command-from-image" },
            BuildEnvironment = new BuildEnvironment {
                // The user of a Docker image asset in the pipeline requires turning on
                // 'dockerEnabledForSelfMutation'.
                BuildImage = LinuxBuildImage.FromAsset(this, "Image", new DockerImageAssetProps {
                    Directory = "./docker-image"
                })
            }
        }) }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
pipeline := pipelines.NewCodePipeline(this, jsii.String("Pipeline"), &CodePipelineProps{
	Synth: pipelines.NewShellStep(jsii.String("Synth"), &ShellStepProps{
		Input: pipelines.CodePipelineSource_Connection(jsii.String("my-org/my-app"), jsii.String("main"), &ConnectionSourceOptions{
			ConnectionArn: jsii.String("arn:aws:codestar-connections:us-east-1:222222222222:connection/7d2469ff-514a-4e4f-9003-5ca4a43cdc41"),
		}),
		Commands: []*string{
			jsii.String("npm ci"),
			jsii.String("npm run build"),
			jsii.String("npx cdk synth"),
		},
	}),

	// Turn this on because the pipeline uses Docker image assets
	DockerEnabledForSelfMutation: jsii.Boolean(true),
})

pipeline.AddWave(jsii.String("MyWave"), &WaveOptions{
	Post: []Step{
		pipelines.NewCodeBuildStep(jsii.String("RunApproval"), &CodeBuildStepProps{
			Commands: []*string{
				jsii.String("command-from-image"),
			},
			BuildEnvironment: &BuildEnvironment{
				// The user of a Docker image asset in the pipeline requires turning on
				// 'dockerEnabledForSelfMutation'.
				BuildImage: codebuild.LinuxBuildImage_FromAsset(this, jsii.String("Image"), &DockerImageAssetProps{
					Directory: jsii.String("./docker-image"),
				}),
			},
		}),
	},
})

Properties ​

buildImageoptionalIBuildImagebuild_imageoptionalIBuildImagebuildImageoptionalIBuildImageBuildImageoptionalIBuildImageBuildImageoptionalIBuildImage= LinuxBuildImage.STANDARD_7_0#
The image used for the builds.
certificateoptionalBuildEnvironmentCertificatecertificateoptionalBuildEnvironmentCertificatecertificateoptionalBuildEnvironmentCertificateCertificateoptionalBuildEnvironmentCertificateCertificateoptionalBuildEnvironmentCertificate#
The location of the PEM-encoded certificate for the build project.

Default: No external certificate is added to the project

computeTypeoptionalComputeTypecompute_typeoptionalComputeTypecomputeTypeoptionalComputeTypeComputeTypeoptionalComputeTypeComputeTypeoptionalComputeType#
The type of compute to use for this build.

Default: taken from #buildImage#defaultComputeType

See the ComputeType enum for the possible values.

dockerServeroptionalDockerServerOptionsdocker_serveroptionalDockerServerOptionsdockerServeroptionalDockerServerOptionsDockerServeroptionalDockerServerOptionsDockerServeroptionalDockerServerOptions#
The Docker server configuration CodeBuild use to build your Docker image.

Default: Doesn't use remote docker server

environmentVariablesoptional{ [key: string]: BuildEnvironmentVariable }environment_variablesoptionaltyping.Mapping[str, BuildEnvironmentVariable]environmentVariablesoptionalMap<String, BuildEnvironmentVariable>EnvironmentVariablesoptionalIDictionary<string, BuildEnvironmentVariable>EnvironmentVariablesoptional*map[string]BuildEnvironmentVariable#
The environment variables that your builds can use.
fleetoptionalIFleetfleetoptionalIFleetfleetoptionalIFleetFleetoptionalIFleetFleetoptionalIFleet#
Fleet resource for a reserved capacity CodeBuild project.

Default: No fleet will be attached to the project, which will remain on-demand.

Fleets allow for process builds or tests to run immediately and reduces build durations, by reserving compute resources for your projects.

You will be charged for the resources in the fleet, even if they are idle.

hostKerneloptionalHostKernelhost_kerneloptionalHostKernelhostKerneloptionalHostKernelHostKerneloptionalHostKernelHostKerneloptionalHostKernel#
The host operating system kernel used for the builds.

Default: the default host kernel chosen by CodeBuild for the build image

notes

The host kernel does not affect the build environment operating system, which is determined by the buildImage.

Only supported by the LINUX_CONTAINER, ARM_CONTAINER, LINUX_EC2 and ARM_EC2 environment types. Not supported by Windows, Lambda or Mac build images.

privilegedoptionalbooleanprivilegedoptionalboolprivilegedoptionalBooleanPrivilegedoptionalboolPrivilegedoptional*bool= false#
Indicates how the project builds Docker images.
notes

Specify true to enable running the Docker daemon inside a Docker container. This value must be set to true only if this build project will be used to build Docker images, and the specified build environment image is not one provided by AWS CodeBuild with Docker support. Otherwise, all associated builds that attempt to interact with the Docker daemon will fail.