@@ -32,6 +32,13 @@ export interface IProject extends IResource, iam.IGrantable {
32
32
/** The IAM service Role of this Project. Undefined for imported Projects. */
33
33
readonly role ?: iam . IRole ;
34
34
35
+ /**
36
+ * Defines a CloudWatch event rule triggered when something happens with this project.
37
+ *
38
+ * @see https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html
39
+ */
40
+ onEvent ( id : string , options : events . OnEventOptions ) : events . Rule ;
41
+
35
42
/**
36
43
* Defines a CloudWatch event rule triggered when the build project state
37
44
* changes. You can filter specific build status events using an event
@@ -57,30 +64,30 @@ export interface IProject extends IResource, iam.IGrantable {
57
64
*
58
65
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html
59
66
*/
60
- onStateChange ( name : string , target ?: events . IRuleTarget , options ? : events . RuleProps ) : events . Rule ;
67
+ onStateChange ( id : string , options : events . OnEventOptions ) : events . Rule ;
61
68
62
69
/**
63
70
* Defines a CloudWatch event rule that triggers upon phase change of this
64
71
* build project.
65
72
*
66
73
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html
67
74
*/
68
- onPhaseChange ( name : string , target ?: events . IRuleTarget , options ? : events . RuleProps ) : events . Rule ;
75
+ onPhaseChange ( id : string , options : events . OnEventOptions ) : events . Rule ;
69
76
70
77
/**
71
78
* Defines an event rule which triggers when a build starts.
72
79
*/
73
- onBuildStarted ( name : string , target ?: events . IRuleTarget , options ? : events . RuleProps ) : events . Rule ;
80
+ onBuildStarted ( id : string , options : events . OnEventOptions ) : events . Rule ;
74
81
75
82
/**
76
83
* Defines an event rule which triggers when a build fails.
77
84
*/
78
- onBuildFailed ( name : string , target ?: events . IRuleTarget , options ? : events . RuleProps ) : events . Rule ;
85
+ onBuildFailed ( id : string , options : events . OnEventOptions ) : events . Rule ;
79
86
80
87
/**
81
88
* Defines an event rule which triggers when a build completes successfully.
82
89
*/
83
- onBuildSucceeded ( name : string , target ?: events . IRuleTarget , options ? : events . RuleProps ) : events . Rule ;
90
+ onBuildSucceeded ( id : string , options : events . OnEventOptions ) : events . Rule ;
84
91
85
92
/**
86
93
* @returns a CloudWatch metric associated with this build project.
@@ -157,6 +164,23 @@ abstract class ProjectBase extends Resource implements IProject {
157
164
/** The IAM service Role of this Project. */
158
165
public abstract readonly role ?: iam . IRole ;
159
166
167
+ /**
168
+ * Defines a CloudWatch event rule triggered when something happens with this project.
169
+ *
170
+ * @see https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html
171
+ */
172
+ public onEvent ( id : string , options : events . OnEventOptions ) : events . Rule {
173
+ const rule = new events . Rule ( this , id , options ) ;
174
+ rule . addTarget ( options . target ) ;
175
+ rule . addEventPattern ( {
176
+ source : [ 'aws.codebuild' ] ,
177
+ detail : {
178
+ 'project-name' : [ this . projectName ]
179
+ }
180
+ } ) ;
181
+ return rule ;
182
+ }
183
+
160
184
/**
161
185
* Defines a CloudWatch event rule triggered when the build project state
162
186
* changes. You can filter specific build status events using an event
@@ -182,17 +206,10 @@ abstract class ProjectBase extends Resource implements IProject {
182
206
*
183
207
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html
184
208
*/
185
- public onStateChange ( name : string , target ?: events . IRuleTarget , options ?: events . RuleProps ) {
186
- const rule = new events . Rule ( this , name , options ) ;
187
- rule . addTarget ( target ) ;
209
+ public onStateChange ( id : string , options : events . OnEventOptions ) {
210
+ const rule = this . onEvent ( id , options ) ;
188
211
rule . addEventPattern ( {
189
- source : [ 'aws.codebuild' ] ,
190
212
detailType : [ 'CodeBuild Build State Change' ] ,
191
- detail : {
192
- 'project-name' : [
193
- this . projectName
194
- ]
195
- }
196
213
} ) ;
197
214
return rule ;
198
215
}
@@ -203,17 +220,10 @@ abstract class ProjectBase extends Resource implements IProject {
203
220
*
204
221
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html
205
222
*/
206
- public onPhaseChange ( name : string , target ?: events . IRuleTarget , options ?: events . RuleProps ) {
207
- const rule = new events . Rule ( this , name , options ) ;
208
- rule . addTarget ( target ) ;
223
+ public onPhaseChange ( id : string , options : events . OnEventOptions ) {
224
+ const rule = this . onEvent ( id , options ) ;
209
225
rule . addEventPattern ( {
210
- source : [ 'aws.codebuild' ] ,
211
226
detailType : [ 'CodeBuild Build Phase Change' ] ,
212
- detail : {
213
- 'project-name' : [
214
- this . projectName
215
- ]
216
- }
217
227
} ) ;
218
228
return rule ;
219
229
}
@@ -224,8 +234,8 @@ abstract class ProjectBase extends Resource implements IProject {
224
234
* To access fields from the event in the event target input,
225
235
* use the static fields on the `StateChangeEvent` class.
226
236
*/
227
- public onBuildStarted ( name : string , target ?: events . IRuleTarget , options ? : events . RuleProps ) {
228
- const rule = this . onStateChange ( name , target , options ) ;
237
+ public onBuildStarted ( id : string , options : events . OnEventOptions ) {
238
+ const rule = this . onStateChange ( id , options ) ;
229
239
rule . addEventPattern ( {
230
240
detail : {
231
241
'build-status' : [ 'IN_PROGRESS' ]
@@ -240,8 +250,8 @@ abstract class ProjectBase extends Resource implements IProject {
240
250
* To access fields from the event in the event target input,
241
251
* use the static fields on the `StateChangeEvent` class.
242
252
*/
243
- public onBuildFailed ( name : string , target ?: events . IRuleTarget , options ? : events . RuleProps ) {
244
- const rule = this . onStateChange ( name , target , options ) ;
253
+ public onBuildFailed ( id : string , options : events . OnEventOptions ) {
254
+ const rule = this . onStateChange ( id , options ) ;
245
255
rule . addEventPattern ( {
246
256
detail : {
247
257
'build-status' : [ 'FAILED' ]
@@ -256,8 +266,8 @@ abstract class ProjectBase extends Resource implements IProject {
256
266
* To access fields from the event in the event target input,
257
267
* use the static fields on the `StateChangeEvent` class.
258
268
*/
259
- public onBuildSucceeded ( name : string , target ?: events . IRuleTarget , options ? : events . RuleProps ) {
260
- const rule = this . onStateChange ( name , target , options ) ;
269
+ public onBuildSucceeded ( id : string , options : events . OnEventOptions ) {
270
+ const rule = this . onStateChange ( id , options ) ;
261
271
rule . addEventPattern ( {
262
272
detail : {
263
273
'build-status' : [ 'SUCCEEDED' ]
0 commit comments