Project

class aws_cdk.aws_codebuild.Project(scope, id, *, artifacts=None, secondary_artifacts=None, secondary_sources=None, source=None, allow_all_outbound=None, badge=None, build_spec=None, cache=None, check_secrets_in_plain_text_env_variables=None, concurrent_build_limit=None, description=None, encryption_key=None, environment=None, environment_variables=None, file_system_locations=None, grant_report_group_permissions=None, logging=None, project_name=None, queued_timeout=None, role=None, security_groups=None, ssm_session_permissions=None, subnet_selection=None, timeout=None, visibility=None, vpc=None)

Bases: Resource

A representation of a CodeBuild Project.

ExampleMetadata:

infused

Example:

# 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"
        )
    )
)
Parameters:
  • scope (Construct) –

  • id (str) –

  • artifacts (Optional[IArtifacts]) – Defines where build artifacts will be stored. Could be: PipelineBuildArtifacts, NoArtifacts and S3Artifacts. Default: NoArtifacts

  • secondary_artifacts (Optional[Sequence[IArtifacts]]) – The secondary artifacts for the Project. Can also be added after the Project has been created by using the Project#addSecondaryArtifact method. Default: - No secondary artifacts.

  • secondary_sources (Optional[Sequence[ISource]]) – The secondary sources for the Project. Can be also added after the Project has been created by using the Project#addSecondarySource method. Default: - No secondary sources.

  • source (Optional[ISource]) – The source of the build. Note: if NoSource is given as the source, then you need to provide an explicit buildSpec. Default: - NoSource

  • allow_all_outbound (Optional[bool]) – Whether to allow the CodeBuild to send all network traffic. If set to false, you must individually add traffic rules to allow the CodeBuild project to connect to network targets. Only used if ‘vpc’ is supplied. Default: true

  • badge (Optional[bool]) – Indicates whether AWS CodeBuild generates a publicly accessible URL for your project’s build badge. For more information, see Build Badges Sample in the AWS CodeBuild User Guide. Default: false

  • build_spec (Optional[BuildSpec]) – Filename or contents of buildspec in JSON format. Default: - Empty buildspec.

  • cache (Optional[Cache]) – Caching strategy to use. Default: Cache.none

  • check_secrets_in_plain_text_env_variables (Optional[bool]) – Whether to check for the presence of any secrets in the environment variables of the default type, BuildEnvironmentVariableType.PLAINTEXT. Since using a secret for the value of that kind of variable would result in it being displayed in plain text in the AWS Console, the construct will throw an exception if it detects a secret was passed there. Pass this property as false if you want to skip this validation, and keep using a secret in a plain text environment variable. Default: true

  • concurrent_build_limit (Union[int, float, None]) – Maximum number of concurrent builds. Minimum value is 1 and maximum is account build limit. Default: - no explicit limit is set

  • description (Optional[str]) – A description of the project. Use the description to identify the purpose of the project. Default: - No description.

  • encryption_key (Optional[IKey]) – Encryption key to use to read and write artifacts. Default: - The AWS-managed CMK for Amazon Simple Storage Service (Amazon S3) is used.

  • environment (Union[BuildEnvironment, Dict[str, Any], None]) – Build environment to use for the build. Default: BuildEnvironment.LinuxBuildImage.STANDARD_7_0

  • environment_variables (Optional[Mapping[str, Union[BuildEnvironmentVariable, Dict[str, Any]]]]) – Additional environment variables to add to the build environment. Default: - No additional environment variables are specified.

  • file_system_locations (Optional[Sequence[IFileSystemLocation]]) – An ProjectFileSystemLocation objects for a CodeBuild build project. A ProjectFileSystemLocation object specifies the identifier, location, mountOptions, mountPoint, and type of a file system created using Amazon Elastic File System. Default: - no file system locations

  • grant_report_group_permissions (Optional[bool]) – Add permissions to this project’s role to create and use test report groups with name starting with the name of this project. That is the standard report group that gets created when a simple name (in contrast to an ARN) is used in the ‘reports’ section of the buildspec of this project. This is usually harmless, but you can turn these off if you don’t plan on using test reports in this project. Default: true

  • logging (Union[LoggingOptions, Dict[str, Any], None]) – Information about logs for the build project. A project can create logs in Amazon CloudWatch Logs, an S3 bucket, or both. Default: - no log configuration is set

  • project_name (Optional[str]) – The physical, human-readable name of the CodeBuild Project. Default: - Name is automatically generated.

  • queued_timeout (Optional[Duration]) – The number of minutes after which AWS CodeBuild stops the build if it’s still in queue. For valid values, see the timeoutInMinutes field in the AWS CodeBuild User Guide. Default: - no queue timeout is set

  • role (Optional[IRole]) – Service Role to assume while running the build. Default: - A role will be created.

  • security_groups (Optional[Sequence[ISecurityGroup]]) – What security group to associate with the codebuild project’s network interfaces. If no security group is identified, one will be created automatically. Only used if ‘vpc’ is supplied. Default: - Security group will be automatically created.

  • ssm_session_permissions (Optional[bool]) – Add the permissions necessary for debugging builds with SSM Session Manager. If the following prerequisites have been met: - The necessary permissions have been added by setting this flag to true. - The build image has the SSM agent installed (true for default CodeBuild images). - The build is started with debugSessionEnabled set to true. Then the build container can be paused and inspected using Session Manager by invoking the codebuild-breakpoint command somewhere during the build. codebuild-breakpoint commands will be ignored if the build is not started with debugSessionEnabled=true. Default: false

  • subnet_selection (Union[SubnetSelection, Dict[str, Any], None]) – Where to place the network interfaces within the VPC. To access AWS services, your CodeBuild project needs to be in one of the following types of subnets: 1. Subnets with access to the internet (of type PRIVATE_WITH_EGRESS). 2. Private subnets unconnected to the internet, but with VPC endpoints for the necessary services. If you don’t specify a subnet selection, the default behavior is to use PRIVATE_WITH_EGRESS subnets first if they exist, then PRIVATE_WITHOUT_EGRESS, and finally PUBLIC subnets. If your VPC doesn’t have PRIVATE_WITH_EGRESS subnets but you need AWS service access, add VPC Endpoints to your private subnets. Default: - private subnets if available else public subnets

  • timeout (Optional[Duration]) – 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. Default: Duration.hours(1)

  • visibility (Optional[ProjectVisibility]) – Specifies the visibility of the project’s builds. Default: - no visibility is set

  • vpc (Optional[IVpc]) – VPC network to place codebuild network interfaces. Specify this if the codebuild project needs to access resources in a VPC. Default: - No VPC is specified.

Methods

add_file_system_location(file_system_location)

Adds a fileSystemLocation to the Project.

Parameters:

file_system_location (IFileSystemLocation) – the fileSystemLocation to add.

Return type:

None

add_secondary_artifact(secondary_artifact)

Adds a secondary artifact to the Project.

Parameters:

secondary_artifact (IArtifacts) – the artifact to add as a secondary artifact.

See:

https://docs.aws.amazon.com/codebuild/latest/userguide/sample-multi-in-out.html

Return type:

None

add_secondary_source(secondary_source)

Adds a secondary source to the Project.

Parameters:

secondary_source (ISource) – the source to add as a secondary source.

See:

https://docs.aws.amazon.com/codebuild/latest/userguide/sample-multi-in-out.html

Return type:

None

add_to_role_policy(statement)

Add a permission only if there’s a policy attached.

Parameters:

statement (PolicyStatement) – The permissions statement to add.

Return type:

None

apply_removal_policy(policy)

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you’ve removed it from the CDK application or because you’ve made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).

Parameters:

policy (RemovalPolicy) –

Return type:

None

bind_as_notification_rule_source(_scope)

Returns a source configuration for notification rule.

Parameters:

_scope (Construct) –

Return type:

NotificationRuleSourceConfig

bind_to_code_pipeline(_scope, *, artifact_bucket)

A callback invoked when the given project is added to a CodePipeline.

Parameters:
  • _scope (Construct) – the construct the binding is taking place in.

  • artifact_bucket (IBucket) – The artifact bucket that will be used by the action that invokes this project.

Return type:

None

enable_batch_builds()

Enable batch builds.

Returns an object contining the batch service role if batch builds could be enabled.

Return type:

Optional[BatchBuildConfig]

metric(metric_name, *, account=None, color=None, dimensions_map=None, label=None, period=None, region=None, statistic=None, unit=None)
Parameters:
  • metric_name (str) – The name of the metric.

  • account (Optional[str]) – Account which this metric comes from. Default: - Deployment account.

  • color (Optional[str]) – The hex color code, prefixed with ‘#’ (e.g. ‘#00ff00’), to use when this metric is rendered on a graph. The Color class has a set of standard colors that can be used here. Default: - Automatic color

  • dimensions_map (Optional[Mapping[str, str]]) – Dimensions of the metric. Default: - No dimensions.

  • label (Optional[str]) – Label for this metric when added to a Graph in a Dashboard. You can use dynamic labels to show summary information about the entire displayed time series in the legend. For example, if you use:: [max: ${MAX}] MyMetric As the metric label, the maximum value in the visible range will be shown next to the time series name in the graph’s legend. Default: - No label

  • period (Optional[Duration]) – The period over which the specified statistic is applied. Default: Duration.minutes(5)

  • region (Optional[str]) – Region which this metric comes from. Default: - Deployment region.

  • statistic (Optional[str]) – What function to use for aggregating. Use the aws_cloudwatch.Stats helper class to construct valid input strings. Can be one of the following: - “Minimum” | “min” - “Maximum” | “max” - “Average” | “avg” - “Sum” | “sum” - “SampleCount | “n” - “pNN.NN” - “tmNN.NN” | “tm(NN.NN%:NN.NN%)” - “iqm” - “wmNN.NN” | “wm(NN.NN%:NN.NN%)” - “tcNN.NN” | “tc(NN.NN%:NN.NN%)” - “tsNN.NN” | “ts(NN.NN%:NN.NN%)” Default: Average

  • unit (Optional[Unit]) – Unit used to filter the metric stream. Only refer to datums emitted to the metric stream with the given unit and ignore all others. Only useful when datums are being emitted to the same metric stream under different units. The default is to use all matric datums in the stream, regardless of unit, which is recommended in nearly all cases. CloudWatch does not honor this property for graphs. Default: - All metric datums in the given metric stream

Return type:

Metric

Returns:

a CloudWatch metric associated with this build project.

metric_builds(*, account=None, color=None, dimensions_map=None, label=None, period=None, region=None, statistic=None, unit=None)

Measures the number of builds triggered.

Units: Count

Valid CloudWatch statistics: Sum

Parameters:
  • account (Optional[str]) – Account which this metric comes from. Default: - Deployment account.

  • color (Optional[str]) – The hex color code, prefixed with ‘#’ (e.g. ‘#00ff00’), to use when this metric is rendered on a graph. The Color class has a set of standard colors that can be used here. Default: - Automatic color

  • dimensions_map (Optional[Mapping[str, str]]) – Dimensions of the metric. Default: - No dimensions.

  • label (Optional[str]) –

    Label for this metric when added to a Graph in a Dashboard. You can use dynamic labels to show summary information about the entire displayed time series in the legend. For example, if you use:: [max: ${MAX}] MyMetric As the metric label, the maximum value in the visible range will be shown next to the time series name in the graph’s legend. Default: - No label

  • period (Optional[Duration]) – The period over which the specified statistic is applied. Default: Duration.minutes(5)

  • region (Optional[str]) – Region which this metric comes from. Default: - Deployment region.

  • statistic (Optional[str]) – What function to use for aggregating. Use the aws_cloudwatch.Stats helper class to construct valid input strings. Can be one of the following: - “Minimum” | “min” - “Maximum” | “max” - “Average” | “avg” - “Sum” | “sum” - “SampleCount | “n” - “pNN.NN” - “tmNN.NN” | “tm(NN.NN%:NN.NN%)” - “iqm” - “wmNN.NN” | “wm(NN.NN%:NN.NN%)” - “tcNN.NN” | “tc(NN.NN%:NN.NN%)” - “tsNN.NN” | “ts(NN.NN%:NN.NN%)” Default: Average

  • unit (Optional[Unit]) – Unit used to filter the metric stream. Only refer to datums emitted to the metric stream with the given unit and ignore all others. Only useful when datums are being emitted to the same metric stream under different units. The default is to use all matric datums in the stream, regardless of unit, which is recommended in nearly all cases. CloudWatch does not honor this property for graphs. Default: - All metric datums in the given metric stream

Default:

sum over 5 minutes

Return type:

Metric

metric_duration(*, account=None, color=None, dimensions_map=None, label=None, period=None, region=None, statistic=None, unit=None)

Measures the duration of all builds over time.

Units: Seconds

Valid CloudWatch statistics: Average (recommended), Maximum, Minimum

Parameters:
  • account (Optional[str]) – Account which this metric comes from. Default: - Deployment account.

  • color (Optional[str]) – The hex color code, prefixed with ‘#’ (e.g. ‘#00ff00’), to use when this metric is rendered on a graph. The Color class has a set of standard colors that can be used here. Default: - Automatic color

  • dimensions_map (Optional[Mapping[str, str]]) – Dimensions of the metric. Default: - No dimensions.

  • label (Optional[str]) –

    Label for this metric when added to a Graph in a Dashboard. You can use dynamic labels to show summary information about the entire displayed time series in the legend. For example, if you use:: [max: ${MAX}] MyMetric As the metric label, the maximum value in the visible range will be shown next to the time series name in the graph’s legend. Default: - No label

  • period (Optional[Duration]) – The period over which the specified statistic is applied. Default: Duration.minutes(5)

  • region (Optional[str]) – Region which this metric comes from. Default: - Deployment region.

  • statistic (Optional[str]) – What function to use for aggregating. Use the aws_cloudwatch.Stats helper class to construct valid input strings. Can be one of the following: - “Minimum” | “min” - “Maximum” | “max” - “Average” | “avg” - “Sum” | “sum” - “SampleCount | “n” - “pNN.NN” - “tmNN.NN” | “tm(NN.NN%:NN.NN%)” - “iqm” - “wmNN.NN” | “wm(NN.NN%:NN.NN%)” - “tcNN.NN” | “tc(NN.NN%:NN.NN%)” - “tsNN.NN” | “ts(NN.NN%:NN.NN%)” Default: Average

  • unit (Optional[Unit]) – Unit used to filter the metric stream. Only refer to datums emitted to the metric stream with the given unit and ignore all others. Only useful when datums are being emitted to the same metric stream under different units. The default is to use all matric datums in the stream, regardless of unit, which is recommended in nearly all cases. CloudWatch does not honor this property for graphs. Default: - All metric datums in the given metric stream

Default:

average over 5 minutes

Return type:

Metric

metric_failed_builds(*, account=None, color=None, dimensions_map=None, label=None, period=None, region=None, statistic=None, unit=None)

Measures the number of builds that failed because of client error or because of a timeout.

Units: Count

Valid CloudWatch statistics: Sum

Parameters:
  • account (Optional[str]) – Account which this metric comes from. Default: - Deployment account.

  • color (Optional[str]) – The hex color code, prefixed with ‘#’ (e.g. ‘#00ff00’), to use when this metric is rendered on a graph. The Color class has a set of standard colors that can be used here. Default: - Automatic color

  • dimensions_map (Optional[Mapping[str, str]]) – Dimensions of the metric. Default: - No dimensions.

  • label (Optional[str]) –

    Label for this metric when added to a Graph in a Dashboard. You can use dynamic labels to show summary information about the entire displayed time series in the legend. For example, if you use:: [max: ${MAX}] MyMetric As the metric label, the maximum value in the visible range will be shown next to the time series name in the graph’s legend. Default: - No label

  • period (Optional[Duration]) – The period over which the specified statistic is applied. Default: Duration.minutes(5)

  • region (Optional[str]) – Region which this metric comes from. Default: - Deployment region.

  • statistic (Optional[str]) – What function to use for aggregating. Use the aws_cloudwatch.Stats helper class to construct valid input strings. Can be one of the following: - “Minimum” | “min” - “Maximum” | “max” - “Average” | “avg” - “Sum” | “sum” - “SampleCount | “n” - “pNN.NN” - “tmNN.NN” | “tm(NN.NN%:NN.NN%)” - “iqm” - “wmNN.NN” | “wm(NN.NN%:NN.NN%)” - “tcNN.NN” | “tc(NN.NN%:NN.NN%)” - “tsNN.NN” | “ts(NN.NN%:NN.NN%)” Default: Average

  • unit (Optional[Unit]) – Unit used to filter the metric stream. Only refer to datums emitted to the metric stream with the given unit and ignore all others. Only useful when datums are being emitted to the same metric stream under different units. The default is to use all matric datums in the stream, regardless of unit, which is recommended in nearly all cases. CloudWatch does not honor this property for graphs. Default: - All metric datums in the given metric stream

Default:

sum over 5 minutes

Return type:

Metric

metric_succeeded_builds(*, account=None, color=None, dimensions_map=None, label=None, period=None, region=None, statistic=None, unit=None)

Measures the number of successful builds.

Units: Count

Valid CloudWatch statistics: Sum

Parameters:
  • account (Optional[str]) – Account which this metric comes from. Default: - Deployment account.

  • color (Optional[str]) – The hex color code, prefixed with ‘#’ (e.g. ‘#00ff00’), to use when this metric is rendered on a graph. The Color class has a set of standard colors that can be used here. Default: - Automatic color

  • dimensions_map (Optional[Mapping[str, str]]) – Dimensions of the metric. Default: - No dimensions.

  • label (Optional[str]) –

    Label for this metric when added to a Graph in a Dashboard. You can use dynamic labels to show summary information about the entire displayed time series in the legend. For example, if you use:: [max: ${MAX}] MyMetric As the metric label, the maximum value in the visible range will be shown next to the time series name in the graph’s legend. Default: - No label

  • period (Optional[Duration]) – The period over which the specified statistic is applied. Default: Duration.minutes(5)

  • region (Optional[str]) – Region which this metric comes from. Default: - Deployment region.

  • statistic (Optional[str]) – What function to use for aggregating. Use the aws_cloudwatch.Stats helper class to construct valid input strings. Can be one of the following: - “Minimum” | “min” - “Maximum” | “max” - “Average” | “avg” - “Sum” | “sum” - “SampleCount | “n” - “pNN.NN” - “tmNN.NN” | “tm(NN.NN%:NN.NN%)” - “iqm” - “wmNN.NN” | “wm(NN.NN%:NN.NN%)” - “tcNN.NN” | “tc(NN.NN%:NN.NN%)” - “tsNN.NN” | “ts(NN.NN%:NN.NN%)” Default: Average

  • unit (Optional[Unit]) – Unit used to filter the metric stream. Only refer to datums emitted to the metric stream with the given unit and ignore all others. Only useful when datums are being emitted to the same metric stream under different units. The default is to use all matric datums in the stream, regardless of unit, which is recommended in nearly all cases. CloudWatch does not honor this property for graphs. Default: - All metric datums in the given metric stream

Default:

sum over 5 minutes

Return type:

Metric

notify_on(id, target, *, events, created_by=None, detail_type=None, enabled=None, notification_rule_name=None)

Defines a CodeStar Notification rule triggered when the project events emitted by you specified, it very similar to onEvent API.

You can also use the methods notifyOnBuildSucceeded and notifyOnBuildFailed to define rules for these specific event emitted.

Parameters:
  • id (str) –

  • target (INotificationRuleTarget) –

  • events (Sequence[ProjectNotificationEvents]) – A list of event types associated with this notification rule for CodeBuild Project. For a complete list of event types and IDs, see Notification concepts in the Developer Tools Console User Guide.

  • created_by (Optional[str]) – The name or email alias of the person who created the notification rule. If not specified, it means that the creator’s alias is not provided. Default: - No alias provided

  • detail_type (Optional[DetailType]) – The level of detail to include in the notifications for this resource. BASIC will include only the contents of the event as it would appear in AWS CloudWatch. FULL will include any supplemental information provided by AWS CodeStar Notifications and/or the service for the resource for which the notification is created. Default: DetailType.FULL

  • enabled (Optional[bool]) – The status of the notification rule. If the enabled is set to DISABLED, notifications aren’t sent for the notification rule. Default: true

  • notification_rule_name (Optional[str]) – The name for the notification rule. Notification rule names must be unique in your AWS account. Default: - generated from the id

Return type:

INotificationRule

notify_on_build_failed(id, target, *, created_by=None, detail_type=None, enabled=None, notification_rule_name=None)

Defines a CodeStar notification rule which triggers when a build fails.

Parameters:
  • id (str) –

  • target (INotificationRuleTarget) –

  • created_by (Optional[str]) – The name or email alias of the person who created the notification rule. If not specified, it means that the creator’s alias is not provided. Default: - No alias provided

  • detail_type (Optional[DetailType]) – The level of detail to include in the notifications for this resource. BASIC will include only the contents of the event as it would appear in AWS CloudWatch. FULL will include any supplemental information provided by AWS CodeStar Notifications and/or the service for the resource for which the notification is created. Default: DetailType.FULL

  • enabled (Optional[bool]) – The status of the notification rule. If the enabled is set to DISABLED, notifications aren’t sent for the notification rule. Default: true

  • notification_rule_name (Optional[str]) – The name for the notification rule. Notification rule names must be unique in your AWS account. Default: - generated from the id

Return type:

INotificationRule

notify_on_build_succeeded(id, target, *, created_by=None, detail_type=None, enabled=None, notification_rule_name=None)

Defines a CodeStar notification rule which triggers when a build completes successfully.

Parameters:
  • id (str) –

  • target (INotificationRuleTarget) –

  • created_by (Optional[str]) – The name or email alias of the person who created the notification rule. If not specified, it means that the creator’s alias is not provided. Default: - No alias provided

  • detail_type (Optional[DetailType]) – The level of detail to include in the notifications for this resource. BASIC will include only the contents of the event as it would appear in AWS CloudWatch. FULL will include any supplemental information provided by AWS CodeStar Notifications and/or the service for the resource for which the notification is created. Default: DetailType.FULL

  • enabled (Optional[bool]) – The status of the notification rule. If the enabled is set to DISABLED, notifications aren’t sent for the notification rule. Default: true

  • notification_rule_name (Optional[str]) – The name for the notification rule. Notification rule names must be unique in your AWS account. Default: - generated from the id

Return type:

INotificationRule

on_build_failed(id, *, target=None, cross_stack_scope=None, description=None, event_pattern=None, rule_name=None)

Defines an event rule which triggers when a build fails.

To access fields from the event in the event target input, use the static fields on the StateChangeEvent class.

Parameters:
  • id (str) –

  • target (Optional[IRuleTarget]) – The target to register for the event. Default: - No target is added to the rule. Use addTarget() to add a target.

  • cross_stack_scope (Optional[Construct]) – The scope to use if the source of the rule and its target are in different Stacks (but in the same account & region). This helps dealing with cycles that often arise in these situations. Default: - none (the main scope will be used, even for cross-stack Events)

  • description (Optional[str]) – A description of the rule’s purpose. Default: - No description

  • event_pattern (Union[EventPattern, Dict[str, Any], None]) – Additional restrictions for the event to route to the specified target. The method that generates the rule probably imposes some type of event filtering. The filtering implied by what you pass here is added on top of that filtering. Default: - No additional filtering based on an event pattern.

  • rule_name (Optional[str]) – A name for the rule. Default: AWS CloudFormation generates a unique physical ID.

Return type:

Rule

on_build_started(id, *, target=None, cross_stack_scope=None, description=None, event_pattern=None, rule_name=None)

Defines an event rule which triggers when a build starts.

To access fields from the event in the event target input, use the static fields on the StateChangeEvent class.

Parameters:
  • id (str) –

  • target (Optional[IRuleTarget]) – The target to register for the event. Default: - No target is added to the rule. Use addTarget() to add a target.

  • cross_stack_scope (Optional[Construct]) – The scope to use if the source of the rule and its target are in different Stacks (but in the same account & region). This helps dealing with cycles that often arise in these situations. Default: - none (the main scope will be used, even for cross-stack Events)

  • description (Optional[str]) – A description of the rule’s purpose. Default: - No description

  • event_pattern (Union[EventPattern, Dict[str, Any], None]) – Additional restrictions for the event to route to the specified target. The method that generates the rule probably imposes some type of event filtering. The filtering implied by what you pass here is added on top of that filtering. Default: - No additional filtering based on an event pattern.

  • rule_name (Optional[str]) – A name for the rule. Default: AWS CloudFormation generates a unique physical ID.

Return type:

Rule

on_build_succeeded(id, *, target=None, cross_stack_scope=None, description=None, event_pattern=None, rule_name=None)

Defines an event rule which triggers when a build completes successfully.

To access fields from the event in the event target input, use the static fields on the StateChangeEvent class.

Parameters:
  • id (str) –

  • target (Optional[IRuleTarget]) – The target to register for the event. Default: - No target is added to the rule. Use addTarget() to add a target.

  • cross_stack_scope (Optional[Construct]) – The scope to use if the source of the rule and its target are in different Stacks (but in the same account & region). This helps dealing with cycles that often arise in these situations. Default: - none (the main scope will be used, even for cross-stack Events)

  • description (Optional[str]) – A description of the rule’s purpose. Default: - No description

  • event_pattern (Union[EventPattern, Dict[str, Any], None]) – Additional restrictions for the event to route to the specified target. The method that generates the rule probably imposes some type of event filtering. The filtering implied by what you pass here is added on top of that filtering. Default: - No additional filtering based on an event pattern.

  • rule_name (Optional[str]) – A name for the rule. Default: AWS CloudFormation generates a unique physical ID.

Return type:

Rule

on_event(id, *, target=None, cross_stack_scope=None, description=None, event_pattern=None, rule_name=None)

Defines a CloudWatch event rule triggered when something happens with this project.

Parameters:
  • id (str) –

  • target (Optional[IRuleTarget]) – The target to register for the event. Default: - No target is added to the rule. Use addTarget() to add a target.

  • cross_stack_scope (Optional[Construct]) – The scope to use if the source of the rule and its target are in different Stacks (but in the same account & region). This helps dealing with cycles that often arise in these situations. Default: - none (the main scope will be used, even for cross-stack Events)

  • description (Optional[str]) – A description of the rule’s purpose. Default: - No description

  • event_pattern (Union[EventPattern, Dict[str, Any], None]) – Additional restrictions for the event to route to the specified target. The method that generates the rule probably imposes some type of event filtering. The filtering implied by what you pass here is added on top of that filtering. Default: - No additional filtering based on an event pattern.

  • rule_name (Optional[str]) – A name for the rule. Default: AWS CloudFormation generates a unique physical ID.

See:

https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html

Return type:

Rule

on_phase_change(id, *, target=None, cross_stack_scope=None, description=None, event_pattern=None, rule_name=None)

Defines a CloudWatch event rule that triggers upon phase change of this build project.

Parameters:
  • id (str) –

  • target (Optional[IRuleTarget]) – The target to register for the event. Default: - No target is added to the rule. Use addTarget() to add a target.

  • cross_stack_scope (Optional[Construct]) – The scope to use if the source of the rule and its target are in different Stacks (but in the same account & region). This helps dealing with cycles that often arise in these situations. Default: - none (the main scope will be used, even for cross-stack Events)

  • description (Optional[str]) – A description of the rule’s purpose. Default: - No description

  • event_pattern (Union[EventPattern, Dict[str, Any], None]) – Additional restrictions for the event to route to the specified target. The method that generates the rule probably imposes some type of event filtering. The filtering implied by what you pass here is added on top of that filtering. Default: - No additional filtering based on an event pattern.

  • rule_name (Optional[str]) – A name for the rule. Default: AWS CloudFormation generates a unique physical ID.

See:

https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html

Return type:

Rule

on_state_change(id, *, target=None, cross_stack_scope=None, description=None, event_pattern=None, rule_name=None)

Defines a CloudWatch event rule triggered when the build project state changes.

You can filter specific build status events using an event pattern filter on the build-status detail field:

const rule = project.onStateChange(‘OnBuildStarted’, { target }); rule.addEventPattern({ detail: { ‘build-status’: [ “IN_PROGRESS”, “SUCCEEDED”, “FAILED”, “STOPPED” ] } });

You can also use the methods onBuildFailed and onBuildSucceeded to define rules for these specific state changes.

To access fields from the event in the event target input, use the static fields on the StateChangeEvent class.

Parameters:
  • id (str) –

  • target (Optional[IRuleTarget]) – The target to register for the event. Default: - No target is added to the rule. Use addTarget() to add a target.

  • cross_stack_scope (Optional[Construct]) – The scope to use if the source of the rule and its target are in different Stacks (but in the same account & region). This helps dealing with cycles that often arise in these situations. Default: - none (the main scope will be used, even for cross-stack Events)

  • description (Optional[str]) – A description of the rule’s purpose. Default: - No description

  • event_pattern (Union[EventPattern, Dict[str, Any], None]) – Additional restrictions for the event to route to the specified target. The method that generates the rule probably imposes some type of event filtering. The filtering implied by what you pass here is added on top of that filtering. Default: - No additional filtering based on an event pattern.

  • rule_name (Optional[str]) – A name for the rule. Default: AWS CloudFormation generates a unique physical ID.

See:

https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html

Return type:

Rule

to_string()

Returns a string representation of this construct.

Return type:

str

Attributes

connections

Access the Connections object.

Will fail if this Project does not have a VPC set.

env

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.

grant_principal

The principal to grant permissions to.

node

The tree node.

project_arn

The ARN of the project.

project_name

The name of the project.

role

The IAM role for this project.

stack

The stack in which this resource is defined.

Static Methods

classmethod from_project_arn(scope, id, project_arn)
Parameters:
  • scope (Construct) –

  • id (str) –

  • project_arn (str) –

Return type:

IProject

classmethod from_project_name(scope, id, project_name)

Import a Project defined either outside the CDK, or in a different CDK Stack (and exported using the export method).

Parameters:
  • scope (Construct) – the parent Construct for this Construct.

  • id (str) – the logical name of this Construct.

  • project_name (str) – the name of the project to import.

Return type:

IProject

Returns:

a reference to the existing Project

Note:

if you’re importing a CodeBuild Project for use in a CodePipeline, make sure the existing Project has permissions to access the S3 Bucket of that Pipeline - otherwise, builds in that Pipeline will always fail.

classmethod is_construct(x)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters:

x (Any) – Any object.

Return type:

bool

Returns:

true if x is an object created from a class which extends Construct.

classmethod is_owned_resource(construct)

Returns true if the construct was created by CDK, and false otherwise.

Parameters:

construct (IConstruct) –

Return type:

bool

classmethod is_resource(construct)

Check whether the given construct is a Resource.

Parameters:

construct (IConstruct) –

Return type:

bool

classmethod serialize_env_variables(environment_variables, validate_no_plain_text_secrets=None, principal=None)

Convert the environment variables map of string to BuildEnvironmentVariable, which is the customer-facing type, to a list of CfnProject.EnvironmentVariableProperty, which is the representation of environment variables in CloudFormation.

Parameters:
  • environment_variables (Mapping[str, Union[BuildEnvironmentVariable, Dict[str, Any]]]) – the map of string to environment variables.

  • validate_no_plain_text_secrets (Optional[bool]) – whether to throw an exception if any of the plain text environment variables contain secrets, defaults to ‘false’.

  • principal (Optional[IGrantable]) –

Return type:

List[EnvironmentVariableProperty]

Returns:

an array of CfnProject.EnvironmentVariableProperty instances