# WindowsBuildImage

A CodeBuild image running Windows.

This class has a bunch of public constants that represent the most popular images.

You can also specify a custom image using one of the static methods:

- WindowsBuildImage.fromDockerRegistry(image[, { secretsManagerCredentials }, imageType])
- WindowsBuildImage.fromEcrRepository(repo[, tag, imageType])
- WindowsBuildImage.fromAsset(parent, id, props, [, imageType])

Implements: [IBuildImage](/cdk/api/v2/docs/aws-cdk-lib.aws_codebuild.IBuildImage.html)

- Source: [`aws-codebuild/lib/project.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-codebuild/lib/project.ts#L2067)
- Type last changed: v2.145.0 · 7 Jun 2024

## Example

TypeScript:

```ts
declare const ecrRepository: ecr.Repository;

new codebuild.Project(this, 'Project', {
  environment: {
    buildImage: codebuild.WindowsBuildImage.fromEcrRepository(ecrRepository, 'v1.0', codebuild.WindowsImageType.SERVER_2019),
    // optional certificate to include in the build image
    certificate: {
      bucket: s3.Bucket.fromBucketName(this, 'Bucket', 'amzn-s3-demo-bucket'),
      objectKey: 'path/to/cert.pem',
    },
  },
  // ...
})
```

Python:

```python
# ecr_repository: ecr.Repository

codebuild.Project(self, "Project",
    environment=codebuild.BuildEnvironment(
        build_image=codebuild.WindowsBuildImage.from_ecr_repository(ecr_repository, "v1.0", codebuild.WindowsImageType.SERVER_2019),
        # optional certificate to include in the build image
        certificate=codebuild.BuildEnvironmentCertificate(
            bucket=s3.Bucket.from_bucket_name(self, "Bucket", "amzn-s3-demo-bucket"),
            object_key="path/to/cert.pem"
        )
    )
)
```

Java:

```java
Repository ecrRepository;

Project.Builder.create(this, "Project")
        .environment(BuildEnvironment.builder()
                .buildImage(WindowsBuildImage.fromEcrRepository(ecrRepository, "v1.0", WindowsImageType.SERVER_2019))
                // optional certificate to include in the build image
                .certificate(BuildEnvironmentCertificate.builder()
                        .bucket(Bucket.fromBucketName(this, "Bucket", "amzn-s3-demo-bucket"))
                        .objectKey("path/to/cert.pem")
                        .build())
                .build())
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
Repository ecrRepository;

new Project(this, "Project", new ProjectProps {
    Environment = new BuildEnvironment {
        BuildImage = WindowsBuildImage.FromEcrRepository(ecrRepository, "v1.0", WindowsImageType.SERVER_2019),
        // optional certificate to include in the build image
        Certificate = new BuildEnvironmentCertificate {
            Bucket = Bucket.FromBucketName(this, "Bucket", "amzn-s3-demo-bucket"),
            ObjectKey = "path/to/cert.pem"
        }
    }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var ecrRepository Repository

codebuild.NewProject(this, jsii.String("Project"), &ProjectProps{
	Environment: &BuildEnvironment{
		BuildImage: codebuild.WindowsBuildImage_FromEcrRepository(ecrRepository, jsii.String("v1.0"), codebuild.WindowsImageType_SERVER_2019),
		// optional certificate to include in the build image
		Certificate: &BuildEnvironmentCertificate{
			Bucket: s3.Bucket_FromBucketName(this, jsii.String("Bucket"), jsii.String("amzn-s3-demo-bucket")),
			ObjectKey: jsii.String("path/to/cert.pem"),
		},
	},
})
```

## Properties

- `defaultComputeType`: [ComputeType](/cdk/api/v2/docs/aws-cdk-lib.aws_codebuild.ComputeType.html) — The default `ComputeType` to use with this image, if one was not specified in `BuildEnvironment#computeType` explicitly.

- `imageId`: string — The Docker image identifier that the build environment uses.

- `imagePullPrincipalType`: [ImagePullPrincipalType](/cdk/api/v2/docs/aws-cdk-lib.aws_codebuild.ImagePullPrincipalType.html) — The type of principal that CodeBuild will use to pull this build Docker image.

- `repository`: [IRepository](/cdk/api/v2/docs/aws-cdk-lib.aws_ecr.IRepository.html) — An optional ECR repository that the image is hosted in.

- `secretsManagerCredentials`: [ISecret](/cdk/api/v2/docs/aws-cdk-lib.aws_secretsmanager.ISecret.html) — The secretsManagerCredentials for access to a private registry.

- `type`: string — The type of build environment.

- `WIN_SERVER_CORE_2019_BASE`: [IBuildImage](/cdk/api/v2/docs/aws-cdk-lib.aws_codebuild.IBuildImage.html) (static) — The standard CodeBuild image `aws/codebuild/windows-base:2019-1.0`, which is based off Windows Server Core 2019.

- `WIN_SERVER_CORE_2019_BASE_2_0`: [IBuildImage](/cdk/api/v2/docs/aws-cdk-lib.aws_codebuild.IBuildImage.html) (static) — The standard CodeBuild image `aws/codebuild/windows-base:2019-2.0`, which is based off Windows Server Core 2019.

- `WIN_SERVER_CORE_2019_BASE_3_0`: [IBuildImage](/cdk/api/v2/docs/aws-cdk-lib.aws_codebuild.IBuildImage.html) (static) — The standard CodeBuild image `aws/codebuild/windows-base:2019-3.0`, which is based off Windows Server Core 2019.

- `WIN_SERVER_CORE_2022_BASE_3_0`: [IBuildImage](/cdk/api/v2/docs/aws-cdk-lib.aws_codebuild.IBuildImage.html) (static) — The standard CodeBuild image `aws/codebuild/windows-base:2022-1.0`, which is based off Windows Server Core 2022.

  Notice: Cannot be used with on-demand compute, only with a {@link BuildEnvironment.fleet}.

- `WINDOWS_BASE_2_0`: [IBuildImage](/cdk/api/v2/docs/aws-cdk-lib.aws_codebuild.IBuildImage.html) (static) — {@link WindowsBuildImage.WIN_SERVER_CORE_2019_BASE_3_0 } should be used instead.

## Methods

- `fromAsset(scope: Construct, id: string, props: DockerImageAssetProps, imageType?: WindowsImageType): IBuildImage` (static) — Uses an Docker image asset as a Windows build image.

- `fromDockerRegistry(name: string, options?: DockerImageOptions, imageType?: WindowsImageType): IBuildImage` (static)

  **Returns:** a Windows build image from a Docker Hub image.

- `fromEcrRepository(repository: IRepository, tagOrDigest?: string, imageType?: WindowsImageType): IBuildImage` (static)

  **Parameters**

  - `repository` — The ECR repository.
  - `tagOrDigest` — Image tag or digest (default "latest", digests must start with `sha256:`).

  **Returns:** A Windows build image from an ECR repository. NOTE: if the repository is external (i.e. imported), then we won't be able to add a resource policy statement for it so CodeBuild can pull the image.

- `runScriptBuildspec(entrypoint: string): BuildSpec` — Make a buildspec to run the indicated script.

- `validate(buildEnvironment: BuildEnvironment): string[]` — Allows the image a chance to validate whether the passed configuration is correct.
