UNPKG

14.8 kBTypeScriptView Raw
1import * as codecommit from '@aws-cdk/aws-codecommit';
2import * as s3 from '@aws-cdk/aws-s3';
3import { CfnProject } from './codebuild.generated';
4import { IProject } from './project';
5import { Construct as CoreConstruct } from '@aws-cdk/core';
6/**
7 * The type returned from {@link ISource#bind}.
8 */
9export interface SourceConfig {
10 readonly sourceProperty: CfnProject.SourceProperty;
11 readonly buildTriggers?: CfnProject.ProjectTriggersProperty;
12 /**
13 * `AWS::CodeBuild::Project.SourceVersion`
14 * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codebuild-project.html#cfn-codebuild-project-sourceversion
15 * @default the latest version
16 */
17 readonly sourceVersion?: string;
18}
19/**
20 * The abstract interface of a CodeBuild source.
21 * Implemented by {@link Source}.
22 */
23export interface ISource {
24 readonly identifier?: string;
25 readonly type: string;
26 readonly badgeSupported: boolean;
27 bind(scope: CoreConstruct, project: IProject): SourceConfig;
28}
29/**
30 * Properties common to all Source classes.
31 */
32export interface SourceProps {
33 /**
34 * The source identifier.
35 * This property is required on secondary sources.
36 */
37 readonly identifier?: string;
38}
39/**
40 * Source provider definition for a CodeBuild Project.
41 */
42export declare abstract class Source implements ISource {
43 static s3(props: S3SourceProps): ISource;
44 static codeCommit(props: CodeCommitSourceProps): ISource;
45 static gitHub(props: GitHubSourceProps): ISource;
46 static gitHubEnterprise(props: GitHubEnterpriseSourceProps): ISource;
47 static bitBucket(props: BitBucketSourceProps): ISource;
48 readonly identifier?: string;
49 abstract readonly type: string;
50 readonly badgeSupported: boolean;
51 protected constructor(props: SourceProps);
52 /**
53 * Called by the project when the source is added so that the source can perform
54 * binding operations on the source. For example, it can grant permissions to the
55 * code build project to read from the S3 bucket.
56 */
57 bind(_scope: CoreConstruct, _project: IProject): SourceConfig;
58}
59/**
60 * The construction properties common to all build sources that are backed by Git.
61 */
62interface GitSourceProps extends SourceProps {
63 /**
64 * The depth of history to download. Minimum value is 0.
65 * If this value is 0, greater than 25, or not provided,
66 * then the full history is downloaded with each build of the project.
67 */
68 readonly cloneDepth?: number;
69 /**
70 * The commit ID, pull request ID, branch name, or tag name that corresponds to
71 * the version of the source code you want to build
72 *
73 * @example 'mybranch'
74 * @default the default branch's HEAD commit ID is used
75 */
76 readonly branchOrRef?: string;
77 /**
78 * Whether to fetch submodules while cloning git repo.
79 *
80 * @default false
81 */
82 readonly fetchSubmodules?: boolean;
83}
84/**
85 * The types of webhook event actions.
86 */
87export declare enum EventAction {
88 /**
89 * A push (of a branch, or a tag) to the repository.
90 */
91 PUSH = "PUSH",
92 /**
93 * Creating a Pull Request.
94 */
95 PULL_REQUEST_CREATED = "PULL_REQUEST_CREATED",
96 /**
97 * Updating a Pull Request.
98 */
99 PULL_REQUEST_UPDATED = "PULL_REQUEST_UPDATED",
100 /**
101 * Merging a Pull Request.
102 */
103 PULL_REQUEST_MERGED = "PULL_REQUEST_MERGED",
104 /**
105 * Re-opening a previously closed Pull Request.
106 * Note that this event is only supported for GitHub and GitHubEnterprise sources.
107 */
108 PULL_REQUEST_REOPENED = "PULL_REQUEST_REOPENED"
109}
110/**
111 * An object that represents a group of filter conditions for a webhook.
112 * Every condition in a given FilterGroup must be true in order for the whole group to be true.
113 * You construct instances of it by calling the {@link #inEventOf} static factory method,
114 * and then calling various `andXyz` instance methods to create modified instances of it
115 * (this class is immutable).
116 *
117 * You pass instances of this class to the `webhookFilters` property when constructing a source.
118 */
119export declare class FilterGroup {
120 /**
121 * Creates a new event FilterGroup that triggers on any of the provided actions.
122 *
123 * @param actions the actions to trigger the webhook on
124 */
125 static inEventOf(...actions: EventAction[]): FilterGroup;
126 private readonly actions;
127 private readonly filters;
128 private constructor();
129 /**
130 * Create a new FilterGroup with an added condition:
131 * the event must affect the given branch.
132 *
133 * @param branchName the name of the branch (can be a regular expression)
134 */
135 andBranchIs(branchName: string): FilterGroup;
136 /**
137 * Create a new FilterGroup with an added condition:
138 * the event must not affect the given branch.
139 *
140 * @param branchName the name of the branch (can be a regular expression)
141 */
142 andBranchIsNot(branchName: string): FilterGroup;
143 /**
144 * Create a new FilterGroup with an added condition:
145 * the event must affect a head commit with the given message.
146 *
147 * @param commitMessage the commit message (can be a regular expression)
148 */
149 andCommitMessageIs(commitMessage: string): FilterGroup;
150 /**
151 * Create a new FilterGroup with an added condition:
152 * the event must not affect a head commit with the given message.
153 *
154 * @param commitMessage the commit message (can be a regular expression)
155 */
156 andCommitMessageIsNot(commitMessage: string): FilterGroup;
157 /**
158 * Create a new FilterGroup with an added condition:
159 * the event must affect the given tag.
160 *
161 * @param tagName the name of the tag (can be a regular expression)
162 */
163 andTagIs(tagName: string): FilterGroup;
164 /**
165 * Create a new FilterGroup with an added condition:
166 * the event must not affect the given tag.
167 *
168 * @param tagName the name of the tag (can be a regular expression)
169 */
170 andTagIsNot(tagName: string): FilterGroup;
171 /**
172 * Create a new FilterGroup with an added condition:
173 * the event must affect a Git reference (ie., a branch or a tag)
174 * that matches the given pattern.
175 *
176 * @param pattern a regular expression
177 */
178 andHeadRefIs(pattern: string): FilterGroup;
179 /**
180 * Create a new FilterGroup with an added condition:
181 * the event must not affect a Git reference (ie., a branch or a tag)
182 * that matches the given pattern.
183 *
184 * @param pattern a regular expression
185 */
186 andHeadRefIsNot(pattern: string): FilterGroup;
187 /**
188 * Create a new FilterGroup with an added condition:
189 * the account ID of the actor initiating the event must match the given pattern.
190 *
191 * @param pattern a regular expression
192 */
193 andActorAccountIs(pattern: string): FilterGroup;
194 /**
195 * Create a new FilterGroup with an added condition:
196 * the account ID of the actor initiating the event must not match the given pattern.
197 *
198 * @param pattern a regular expression
199 */
200 andActorAccountIsNot(pattern: string): FilterGroup;
201 /**
202 * Create a new FilterGroup with an added condition:
203 * the Pull Request that is the source of the event must target the given base branch.
204 * Note that you cannot use this method if this Group contains the `PUSH` event action.
205 *
206 * @param branchName the name of the branch (can be a regular expression)
207 */
208 andBaseBranchIs(branchName: string): FilterGroup;
209 /**
210 * Create a new FilterGroup with an added condition:
211 * the Pull Request that is the source of the event must not target the given base branch.
212 * Note that you cannot use this method if this Group contains the `PUSH` event action.
213 *
214 * @param branchName the name of the branch (can be a regular expression)
215 */
216 andBaseBranchIsNot(branchName: string): FilterGroup;
217 /**
218 * Create a new FilterGroup with an added condition:
219 * the Pull Request that is the source of the event must target the given Git reference.
220 * Note that you cannot use this method if this Group contains the `PUSH` event action.
221 *
222 * @param pattern a regular expression
223 */
224 andBaseRefIs(pattern: string): FilterGroup;
225 /**
226 * Create a new FilterGroup with an added condition:
227 * the Pull Request that is the source of the event must not target the given Git reference.
228 * Note that you cannot use this method if this Group contains the `PUSH` event action.
229 *
230 * @param pattern a regular expression
231 */
232 andBaseRefIsNot(pattern: string): FilterGroup;
233 /**
234 * Create a new FilterGroup with an added condition:
235 * the push that is the source of the event must affect a file that matches the given pattern.
236 * Note that you can only use this method if this Group contains only the `PUSH` event action,
237 * and only for GitHub, Bitbucket and GitHubEnterprise sources.
238 *
239 * @param pattern a regular expression
240 */
241 andFilePathIs(pattern: string): FilterGroup;
242 /**
243 * Create a new FilterGroup with an added condition:
244 * the push that is the source of the event must not affect a file that matches the given pattern.
245 * Note that you can only use this method if this Group contains only the `PUSH` event action,
246 * and only for GitHub, Bitbucket and GitHubEnterprise sources.
247 *
248 * @param pattern a regular expression
249 */
250 andFilePathIsNot(pattern: string): FilterGroup;
251 /** @internal */
252 get _actions(): EventAction[];
253 /** @internal */
254 get _filters(): CfnProject.WebhookFilterProperty[];
255 /** @internal */
256 _toJson(): CfnProject.WebhookFilterProperty[];
257 private addCommitMessageFilter;
258 private addHeadBranchFilter;
259 private addHeadTagFilter;
260 private addHeadRefFilter;
261 private addActorAccountId;
262 private addBaseBranchFilter;
263 private addBaseRefFilter;
264 private addFilePathFilter;
265 private addFilter;
266}
267/**
268 * The construction properties common to all third-party build sources that are backed by Git.
269 */
270interface ThirdPartyGitSourceProps extends GitSourceProps {
271 /**
272 * Whether to send notifications on your build's start and end.
273 *
274 * @default true
275 */
276 readonly reportBuildStatus?: boolean;
277 /**
278 * Whether to create a webhook that will trigger a build every time an event happens in the repository.
279 *
280 * @default true if any `webhookFilters` were provided, false otherwise
281 */
282 readonly webhook?: boolean;
283 /**
284 * Trigger a batch build from a webhook instead of a standard one.
285 *
286 * Enabling this will enable batch builds on the CodeBuild project.
287 *
288 * @default false
289 */
290 readonly webhookTriggersBatchBuild?: boolean;
291 /**
292 * A list of webhook filters that can constraint what events in the repository will trigger a build.
293 * A build is triggered if any of the provided filter groups match.
294 * Only valid if `webhook` was not provided as false.
295 *
296 * @default every push and every Pull Request (create or update) triggers a build
297 */
298 readonly webhookFilters?: FilterGroup[];
299 /**
300 * The URL that the build will report back to the source provider.
301 * Can use built-in CodeBuild variables, like $AWS_REGION.
302 *
303 * @see https://docs.aws.amazon.com/codebuild/latest/userguide/create-project-cli.html#cli.source.buildstatusconfig.targeturl
304 * @see https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
305 *
306 * @example "$CODEBUILD_PUBLIC_BUILD_URL"
307 * @default - link to the AWS Console for CodeBuild to a particular build execution
308 */
309 readonly buildStatusUrl?: string;
310}
311/**
312 * Construction properties for {@link CodeCommitSource}.
313 */
314export interface CodeCommitSourceProps extends GitSourceProps {
315 readonly repository: codecommit.IRepository;
316}
317/**
318 * Construction properties for {@link S3Source}.
319 */
320export interface S3SourceProps extends SourceProps {
321 readonly bucket: s3.IBucket;
322 readonly path: string;
323 /**
324 * The version ID of the object that represents the build input ZIP file to use.
325 *
326 * @default latest
327 */
328 readonly version?: string;
329}
330/**
331 * Common properties between {@link GitHubSource} and {@link GitHubEnterpriseSource}.
332 */
333interface CommonGithubSourceProps extends ThirdPartyGitSourceProps {
334 /**
335 * This parameter is used for the `context` parameter in the GitHub commit status.
336 * Can use built-in CodeBuild variables, like $AWS_REGION.
337 *
338 * @see https://docs.aws.amazon.com/codebuild/latest/userguide/create-project-cli.html#cli.source.buildstatusconfig.context
339 * @see https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
340 *
341 * @example "My build #$CODEBUILD_BUILD_NUMBER"
342 * @default "AWS CodeBuild $AWS_REGION ($PROJECT_NAME)"
343 */
344 readonly buildStatusContext?: string;
345}
346/**
347 * Construction properties for {@link GitHubSource} and {@link GitHubEnterpriseSource}.
348 */
349export interface GitHubSourceProps extends CommonGithubSourceProps {
350 /**
351 * The GitHub account/user that owns the repo.
352 *
353 * @example 'awslabs'
354 */
355 readonly owner: string;
356 /**
357 * The name of the repo (without the username).
358 *
359 * @example 'aws-cdk'
360 */
361 readonly repo: string;
362}
363/**
364 * Construction properties for {@link GitHubEnterpriseSource}.
365 */
366export interface GitHubEnterpriseSourceProps extends CommonGithubSourceProps {
367 /**
368 * The HTTPS URL of the repository in your GitHub Enterprise installation.
369 */
370 readonly httpsCloneUrl: string;
371 /**
372 * Whether to ignore SSL errors when connecting to the repository.
373 *
374 * @default false
375 */
376 readonly ignoreSslErrors?: boolean;
377}
378/**
379 * Construction properties for {@link BitBucketSource}.
380 */
381export interface BitBucketSourceProps extends ThirdPartyGitSourceProps {
382 /**
383 * The BitBucket account/user that owns the repo.
384 *
385 * @example 'awslabs'
386 */
387 readonly owner: string;
388 /**
389 * The name of the repo (without the username).
390 *
391 * @example 'aws-cdk'
392 */
393 readonly repo: string;
394 /**
395 * This parameter is used for the `name` parameter in the Bitbucket commit status.
396 * Can use built-in CodeBuild variables, like $AWS_REGION.
397 *
398 * @see https://docs.aws.amazon.com/codebuild/latest/userguide/create-project-cli.html#cli.source.buildstatusconfig.context
399 * @see https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
400 *
401 * @example "My build #$CODEBUILD_BUILD_NUMBER"
402 * @default "AWS CodeBuild $AWS_REGION ($PROJECT_NAME)"
403 */
404 readonly buildStatusName?: string;
405}
406export {};