CodeBuildProject Class
Start a CodeBuild build when an Amazon EventBridge rule is triggered.
Example
ts
import * as sns from 'aws-cdk-lib/aws-sns';
import * as targets from 'aws-cdk-lib/aws-events-targets';
declare const repo: codecommit.Repository;
declare const project: codebuild.PipelineProject;
declare const myTopic: sns.Topic;
// starts a CodeBuild project when a commit is pushed to the "main" branch of the repo
repo.onCommit('CommitToMain', {
target: new targets.CodeBuildProject(project),
branches: ['main'],
});
// publishes a message to an Amazon SNS topic when a comment is made on a pull request
const rule = repo.onCommentOnPullRequest('CommentOnPullRequest', {
target: new targets.SnsTopic(myTopic),
});
python
import aws_cdk.aws_sns as sns
import aws_cdk.aws_events_targets as targets
# repo: codecommit.Repository
# project: codebuild.PipelineProject
# my_topic: sns.Topic
# starts a CodeBuild project when a commit is pushed to the "main" branch of the repo
repo.on_commit("CommitToMain",
target=targets.CodeBuildProject(project),
branches=["main"]
)
# publishes a message to an Amazon SNS topic when a comment is made on a pull request
rule = repo.on_comment_on_pull_request("CommentOnPullRequest",
target=targets.SnsTopic(my_topic)
)
java
import software.amazon.awscdk.services.sns.*;
import software.amazon.awscdk.services.events.targets.*;
Repository repo;
PipelineProject project;
Topic myTopic;
// starts a CodeBuild project when a commit is pushed to the "main" branch of the repo
repo.onCommit("CommitToMain", OnCommitOptions.builder()
.target(new CodeBuildProject(project))
.branches(List.of("main"))
.build());
// publishes a message to an Amazon SNS topic when a comment is made on a pull request
Rule rule = repo.onCommentOnPullRequest("CommentOnPullRequest", OnEventOptions.builder()
.target(new SnsTopic(myTopic))
.build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.SNS;
using Amazon.CDK.AWS.Events.Targets;
Repository repo;
PipelineProject project;
Topic myTopic;
// starts a CodeBuild project when a commit is pushed to the "main" branch of the repo
repo.OnCommit("CommitToMain", new OnCommitOptions {
Target = new CodeBuildProject(project),
Branches = new [] { "main" }
});
// publishes a message to an Amazon SNS topic when a comment is made on a pull request
var rule = repo.OnCommentOnPullRequest("CommentOnPullRequest", new OnEventOptions {
Target = new SnsTopic(myTopic)
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import sns "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
var repo Repository
var project PipelineProject
var myTopic Topic
// starts a CodeBuild project when a commit is pushed to the "main" branch of the repo
repo.onCommit(jsii.String("CommitToMain"), &OnCommitOptions{
Target: targets.NewCodeBuildProject(project),
Branches: []*string{
jsii.String("main"),
},
})
// publishes a message to an Amazon SNS topic when a comment is made on a pull request
rule := repo.onCommentOnPullRequest(jsii.String("CommentOnPullRequest"), &OnEventOptions{
Target: targets.NewSnsTopic(myTopic),
})
Initializer
ts
new CodeBuildProject(project: IProjectRef, props?: CodeBuildProjectProps)
python
CodeBuildProject(project: IProjectRef, props: typing.Optional[CodeBuildProjectProps] = None)
java
new CodeBuildProject(IProjectRef project, CodeBuildProjectProps props)
csharp
new CodeBuildProject(IProjectRef project, CodeBuildProjectProps? props = null)
go
NewCodeBuildProject(Project IProjectRef, Props CodeBuildProjectProps)
Methods
bind(_rule: IRuleRef, _id?: string): RuleTargetConfigdef bind(self, _rule: IRuleRef, _id: typing.Optional[str] = None) -> RuleTargetConfigpublic RuleTargetConfig bind(IRuleRef _rule, String _id)public RuleTargetConfig Bind(IRuleRef _rule, string? _id = null)func Bind(_rule IRuleRef, _id *string) RuleTargetConfig#Allows using build projects as event rule targets.