diff --git a/packages/@aws-cdk/aws-codebuild/lib/project.ts b/packages/@aws-cdk/aws-codebuild/lib/project.ts index 8bfc8f38e09cf..8ac10c718953e 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/project.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/project.ts @@ -396,14 +396,11 @@ abstract class ProjectBase extends Resource implements IProject { } } -export interface CommonProjectProps { - /** - * A description of the project. Use the description to identify the purpose - * of the project. - * - * @default - No description. - */ - readonly description?: string; +/** + * Common override properties of the CodeBuild project + * TODO: add properties `queuedTimeoutInMinutes`, `logsConfig` + */ +interface CommonStartBuildOptions { /** * Filename or contents of buildspec in JSON format. @@ -413,13 +410,6 @@ export interface CommonProjectProps { */ readonly buildSpec?: BuildSpec; - /** - * Service Role to assume while running the build. - * - * @default - A role will be created. - */ - readonly role?: iam.IRole; - /** * Encryption key to use to read and write artifacts. * @@ -442,13 +432,11 @@ export interface CommonProjectProps { readonly environment?: BuildEnvironment; /** - * 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. + * Service Role to assume while running the build. * - * @default false + * @default - A role will be created. */ - readonly badge?: boolean; + readonly role?: iam.IRole; /** * The number of minutes after which AWS CodeBuild stops the build if it's @@ -465,6 +453,28 @@ export interface CommonProjectProps { * @default - No additional environment variables are specified. */ readonly environmentVariables?: { [name: string]: BuildEnvironmentVariable }; +} + +/** + * Common properties of the CodeBuild project + */ +export interface CommonProjectProps extends CommonStartBuildOptions { + /** + * A description of the project. Use the description to identify the purpose + * of the project. + * + * @default - No description. + */ + readonly description?: string; + + /** + * 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 + */ + readonly badge?: boolean; /** * The physical, human-readable name of the CodeBuild Project. @@ -540,7 +550,10 @@ export interface CommonProjectProps { readonly grantReportGroupPermissions?: boolean; } -export interface ProjectProps extends CommonProjectProps { +/** + * Override properties of the CodeBuild project + */ +export interface StartBuildOptions extends CommonStartBuildOptions { /** * The source of the build. * *Note*: if {@link NoSource} is given as the source, @@ -577,6 +590,12 @@ export interface ProjectProps extends CommonProjectProps { readonly secondaryArtifacts?: IArtifacts[]; } +/** + * Properties of the CodeBuild project + */ +export interface ProjectProps extends StartBuildOptions, CommonProjectProps { +} + /** * The extra options passed to the {@link IProject.bindToCodePipeline} method. */ diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/README.md b/packages/@aws-cdk/aws-stepfunctions-tasks/README.md index 269135eed0652..8a9a0866560e8 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/README.md +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/README.md @@ -342,11 +342,18 @@ const codebuildProject = new codebuild.Project(stack, 'Project', { const task = new tasks.CodeBuildStartBuild(stack, 'Task', { project: codebuildProject, integrationPattern: sfn.IntegrationPattern.RUN_JOB, - environmentVariablesOverride: { - ZONE: { - type: codebuild.BuildEnvironmentVariableType.PLAINTEXT, - value: sfn.JsonPath.stringAt('$.envVariables.zone'), + overrides: { + environmentVariables: { + ZONE: { + type: codebuild.BuildEnvironmentVariableType.PLAINTEXT, + value: sfn.JsonPath.stringAt('$.envVariables.zone'), + }, }, + source: codebuild.Source.gitHub({ + branchOrRef: sfn.JsonPath.stringAt('$.commitHash'), + owner, + repo, + }), }, }); ``` diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/codebuild/start-build.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/codebuild/start-build.ts index 939732e237d54..997d25b11a296 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/codebuild/start-build.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/codebuild/start-build.ts @@ -5,6 +5,26 @@ import * as cdk from '@aws-cdk/core'; import { Construct } from 'constructs'; import { integrationResourceArn, validatePatternSupported } from '../private/task-utils'; +/** + * Override properties for CodeBuildStartBuild + * + */ +export interface OverrideProjectProps extends codebuild.StartBuildOptions { + /** + * Specifies if session debugging is enabled for this build. + * + * @default - the session debugging is disabled. + */ + readonly debugSessionEnabled?: boolean; + + /** + * A unique, case sensitive identifier you provide to ensure the idempotency of the StartBuild request. + * + * @default - no idempotency token. + */ + readonly idempotencyToken?: string; +} + /** * Properties for CodeBuildStartBuild */ @@ -13,12 +33,21 @@ export interface CodeBuildStartBuildProps extends sfn.TaskStateBaseProps { * CodeBuild project to start */ readonly project: codebuild.IProject; + /** * A set of environment variables to be used for this build only. * + * @deprecated - use {@link OverrideProjectProps.environmentVariables} instead * @default - the latest environment variables already defined in the build project. */ readonly environmentVariablesOverride?: { [name: string]: codebuild.BuildEnvironmentVariable }; + + /** + * Override properties of the build of CodeBuild. + * + * @default - no override properties. + */ + readonly overrides?: OverrideProjectProps; } /** @@ -42,6 +71,7 @@ export class CodeBuildStartBuild extends sfn.TaskStateBase { this.integrationPattern = props.integrationPattern ?? sfn.IntegrationPattern.REQUEST_RESPONSE; validatePatternSupported(this.integrationPattern, CodeBuildStartBuild.SUPPORTED_INTEGRATION_PATTERNS); + this.validateOverridingParameters(props); this.taskMetrics = { metricPrefixSingular: 'CodeBuildProject', @@ -91,13 +121,52 @@ export class CodeBuildStartBuild extends sfn.TaskStateBase { * @internal */ protected _renderTask(): any { + const sourceConfig = this.props.overrides?.source?.bind(this.props.project.stack, this.props.project); + const secondarySources = this.props.overrides?.secondarySources?.map(source => source.bind(this.props.project.stack, this.props.project)); return { Resource: integrationResourceArn('codebuild', 'startBuild', this.integrationPattern), Parameters: sfn.FieldUtils.renderObject({ ProjectName: this.props.project.projectName, - EnvironmentVariablesOverride: this.props.environmentVariablesOverride - ? this.serializeEnvVariables(this.props.environmentVariablesOverride) - : undefined, + ArtifactsOverride: this.props.overrides?.artifacts?.bind(this.props.project.stack, this.props.project).artifactsProperty, + BuildspecOverride: this.props.overrides?.buildSpec?.toBuildSpec(), + BuildStatusConfigOverride: sourceConfig?.sourceProperty.buildStatusConfig, + ComputeTypeOverride: this.props.overrides?.environment?.computeType, + DebugSessionEnabled: this.props.overrides?.debugSessionEnabled, + EncryptionKeyOverride: this.props.overrides?.encryptionKey?.keyArn, + EnvironmentTypeOverride: this.props.overrides?.environment?.buildImage?.type, + EnvironmentVariablesOverride: this.props.overrides?.environmentVariables ? + this.serializeEnvVariables(this.props.overrides?.environmentVariables!) : + (this.props.environmentVariablesOverride + ? this.serializeEnvVariables(this.props.environmentVariablesOverride) + : undefined), + GitCloneDepthOverride: sourceConfig?.sourceProperty.gitCloneDepth, + GitSubmodulesConfigOverride: sourceConfig?.sourceProperty.gitSubmodulesConfig, + IdempotencyToken: this.props.overrides?.idempotencyToken, + ImageOverride: this.props.overrides?.environment?.buildImage?.imageId, + ImagePullCredentialsTypeOverride: this.props.overrides?.environment?.buildImage?.imagePullPrincipalType, + InsecureSslOverride: sourceConfig?.sourceProperty.insecureSsl, + PrivilegedModeOverride: this.props.overrides?.environment?.privileged, + RegistryCredentialOverride: this.props.overrides?.environment?.buildImage?.secretsManagerCredentials ? { + credentialProvider: 'SECRETS_MANAGER', + credential: this.props.overrides!.environment!.buildImage!.secretsManagerCredentials.secretArn, + } : undefined, + ReportBuildStatusOverride: sourceConfig?.sourceProperty.reportBuildStatus, + SecondaryArtifactsOverride: this.props.overrides?.secondaryArtifacts?.map(artifact => + artifact.bind(this.props.project.stack, this.props.project).artifactsProperty, + ), + SecondarySourcesOverride: secondarySources?.map(source => source.sourceProperty), + SecondarySourcesVersionOverride: secondarySources?.map(source => { + return { + sourceIdentifier: source.sourceProperty.sourceIdentifier, + sourceVersion: source.sourceVersion, + }; + }), + ServiceRoleOverride: this.props.overrides?.role?.roleArn, + SourceAuthOverride: sourceConfig?.sourceProperty.auth, + SourceLocationOverride: sourceConfig?.sourceProperty.location, + SourceTypeOverride: this.props.overrides?.source?.type, + SourceVersion: sourceConfig?.sourceVersion, + TimeoutInMinutesOverride: this.props.overrides?.timeout?.toMinutes(), }), }; } @@ -109,4 +178,17 @@ export class CodeBuildStartBuild extends sfn.TaskStateBase { Value: environmentVariables[name].value, })); } + + private validateOverridingParameters(props: CodeBuildStartBuildProps) { + if (props.overrides?.secondaryArtifacts && props.overrides!.secondaryArtifacts!.length > 12) { + throw new Error(`The maximum overrides that can be specified for 'secondaryArtifacts' is 12. Received: ${props.overrides!.secondaryArtifacts!.length}`); + } + if (props.overrides?.secondarySources && props.overrides!.secondarySources!.length > 12) { + throw new Error(`The maximum overrides that can be specified for 'secondarySources' is 12. Received: ${props.overrides!.secondarySources!.length}`); + } + if (props.overrides?.timeout && (props.overrides!.timeout!.toMinutes() < 5 + || props.overrides!.timeout!.toMinutes() > 480)) { + throw new Error('The value of override property "timeout" must be between 5 and 480 minutes.'); + } + } } diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/codebuild/integ.start-build-override-options.expected.json b/packages/@aws-cdk/aws-stepfunctions-tasks/test/codebuild/integ.start-build-override-options.expected.json new file mode 100644 index 0000000000000..86d331d57d75e --- /dev/null +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/codebuild/integ.start-build-override-options.expected.json @@ -0,0 +1,267 @@ +{ + "Resources": { + "ProjectRole4CCB274E": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "codebuild.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "ProjectRoleDefaultPolicy7F29461B": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "logs:CreateLogGroup", + "logs:CreateLogStream", + "logs:PutLogEvents" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":logs:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":log-group:/aws/codebuild/", + { + "Ref": "ProjectC78D97AD" + } + ] + ] + }, + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":logs:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":log-group:/aws/codebuild/", + { + "Ref": "ProjectC78D97AD" + }, + ":*" + ] + ] + } + ] + }, + { + "Action": [ + "codebuild:CreateReportGroup", + "codebuild:CreateReport", + "codebuild:UpdateReport", + "codebuild:BatchPutTestCases", + "codebuild:BatchPutCodeCoverages" + ], + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":codebuild:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":report-group/", + { + "Ref": "ProjectC78D97AD" + }, + "-*" + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "ProjectRoleDefaultPolicy7F29461B", + "Roles": [ + { + "Ref": "ProjectRole4CCB274E" + } + ] + } + }, + "ProjectC78D97AD": { + "Type": "AWS::CodeBuild::Project", + "Properties": { + "Artifacts": { + "Type": "NO_ARTIFACTS" + }, + "Environment": { + "ComputeType": "BUILD_GENERAL1_SMALL", + "EnvironmentVariables": [ + { + "Name": "zone", + "Type": "PLAINTEXT", + "Value": "defaultZone" + } + ], + "Image": "aws/codebuild/standard:1.0", + "ImagePullCredentialsType": "CODEBUILD", + "PrivilegedMode": false, + "Type": "LINUX_CONTAINER" + }, + "ServiceRole": { + "Fn::GetAtt": [ + "ProjectRole4CCB274E", + "Arn" + ] + }, + "Source": { + "BuildSpec": "{\n \"version\": \"0.2\",\n \"phases\": {\n \"build\": {\n \"commands\": [\n \"echo \\\"Hello, CodeBuild!\\\"\"\n ]\n }\n }\n}", + "Type": "GITHUB", + "Location": "https://github.com/aws/aws-cdk.git", + "ReportBuildStatus": true + }, + "SourceVersion": "master", + "Name": "MyTestProject", + "EncryptionKey": "alias/aws/s3" + } + }, + "StateMachineRoleB840431D": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": { + "Fn::Join": [ + "", + [ + "states.", + { + "Ref": "AWS::Region" + }, + ".amazonaws.com" + ] + ] + } + } + } + ], + "Version": "2012-10-17" + } + } + }, + "StateMachineRoleDefaultPolicyDF1E6607": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "codebuild:StartBuild", + "codebuild:StopBuild", + "codebuild:BatchGetBuilds", + "codebuild:BatchGetReports" + ], + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "ProjectC78D97AD", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRoleDefaultPolicyDF1E6607", + "Roles": [ + { + "Ref": "StateMachineRoleB840431D" + } + ] + } + }, + "StateMachine2E01A3A5": { + "Type": "AWS::StepFunctions::StateMachine", + "Properties": { + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRoleB840431D", + "Arn" + ] + }, + "DefinitionString": { + "Fn::Join": [ + "", + [ + "{\"StartAt\":\"Start\",\"States\":{\"Start\":{\"Type\":\"Pass\",\"Result\":{\"bar\":\"SomeValue\"},\"Next\":\"build-task\"},\"build-task\":{\"End\":true,\"Type\":\"Task\",\"Resource\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":states:::codebuild:startBuild\",\"Parameters\":{\"ProjectName\":\"", + { + "Ref": "ProjectC78D97AD" + }, + "\",\"ComputeTypeOverride\":\"BUILD_GENERAL1_2XLARGE\",\"EnvironmentVariablesOverride\":[{\"Name\":\"ZONE\",\"Type\":\"PLAINTEXT\",\"Value.$\":\"$.envVariables.zone\"}],\"ReportBuildStatusOverride\":true,\"SourceLocationOverride\":\"https://github.com/aws/aws-cdk.git\",\"SourceTypeOverride\":\"GITHUB\",\"SourceVersion.$\":\"$.sourceCommit\"}}}}" + ] + ] + } + }, + "DependsOn": [ + "StateMachineRoleDefaultPolicyDF1E6607", + "StateMachineRoleB840431D" + ] + } + }, + "Outputs": { + "ProjectName": { + "Value": { + "Ref": "ProjectC78D97AD" + } + }, + "StateMachineArn": { + "Value": { + "Ref": "StateMachine2E01A3A5" + } + } + } +} diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/codebuild/integ.start-build-override-options.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/codebuild/integ.start-build-override-options.ts new file mode 100644 index 0000000000000..7dba5af9551d9 --- /dev/null +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/codebuild/integ.start-build-override-options.ts @@ -0,0 +1,88 @@ +import * as codebuild from '@aws-cdk/aws-codebuild'; +import * as sfn from '@aws-cdk/aws-stepfunctions'; +import * as cdk from '@aws-cdk/core'; +import * as tasks from '../../lib'; + +/* + * Stack verification steps: + * * aws stepfunctions start-execution --state-machine-arn : should return execution arn + * * aws codebuild list-builds-for-project --project-name : should return a list of projects with size greater than 0 + * * + * * aws codebuild batch-get-builds --ids --query 'builds[0].buildStatus': wait until the status is 'SUCCEEDED' + * * aws stepfunctions describe-execution --execution-arn --query 'status': should return status as SUCCEEDED + */ + +class StartBuildStack extends cdk.Stack { + constructor(scope: cdk.App, id: string, props: cdk.StackProps = {}) { + super(scope, id, props); + + const owner = 'aws'; + const repo = 'aws-cdk'; + const source = codebuild.Source.gitHub({ + owner, + repo, + branchOrRef: 'master', + }); + + let project = new codebuild.Project(this, 'Project', { + projectName: 'MyTestProject', + source, + buildSpec: codebuild.BuildSpec.fromObject({ + version: '0.2', + phases: { + build: { + commands: [ + 'echo "Hello, CodeBuild!"', + ], + }, + }, + }), + environmentVariables: { + zone: { + type: codebuild.BuildEnvironmentVariableType.PLAINTEXT, + value: 'defaultZone', + }, + }, + }); + + const sourceOverride = codebuild.Source.gitHub({ + branchOrRef: sfn.JsonPath.stringAt('$.sourceCommit'), + owner, + repo, + }); + let startBuild = new tasks.CodeBuildStartBuild(this, 'build-task', { + project: project, + overrides: { + source: sourceOverride, + environment: { + computeType: codebuild.ComputeType.X2_LARGE, + }, + environmentVariables: { + ZONE: { + type: codebuild.BuildEnvironmentVariableType.PLAINTEXT, + value: sfn.JsonPath.stringAt('$.envVariables.zone'), + }, + }, + }, + }); + + const definition = new sfn.Pass(this, 'Start', { + result: sfn.Result.fromObject({ bar: 'SomeValue' }), + }).next(startBuild); + + const stateMachine = new sfn.StateMachine(this, 'StateMachine', { + definition, + }); + + new cdk.CfnOutput(this, 'ProjectName', { + value: project.projectName, + }); + new cdk.CfnOutput(this, 'StateMachineArn', { + value: stateMachine.stateMachineArn, + }); + } +} + +const app = new cdk.App(); +new StartBuildStack(app, 'aws-stepfunctions-tasks-codebuild-start-build-integ'); +app.synth(); diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/codebuild/start-build.test.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/codebuild/start-build.test.ts index 0c71117392c5e..7dde84a1507f8 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/codebuild/start-build.test.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/codebuild/start-build.test.ts @@ -1,4 +1,5 @@ import * as codebuild from '@aws-cdk/aws-codebuild'; +import * as s3 from '@aws-cdk/aws-s3'; import * as sfn from '@aws-cdk/aws-stepfunctions'; import * as cdk from '@aws-cdk/core'; import { CodeBuildStartBuild } from '../../lib'; @@ -56,7 +57,53 @@ test('Task with only the required parameters', () => { }); }); -test('Task with all the parameters', () => { +test('Task with env variables parameters', () => { + // WHEN + const task = new CodeBuildStartBuild(stack, 'Task', { + project: codebuildProject, + integrationPattern: sfn.IntegrationPattern.RUN_JOB, + overrides: { + environmentVariables: { + env: { + type: codebuild.BuildEnvironmentVariableType.PLAINTEXT, + value: 'prod', + }, + }, + }, + }); + + // THEN + expect(stack.resolve(task.toStateJson())).toEqual({ + Type: 'Task', + Resource: { + 'Fn::Join': [ + '', + [ + 'arn:', + { + Ref: 'AWS::Partition', + }, + ':states:::codebuild:startBuild.sync', + ], + ], + }, + End: true, + Parameters: { + ProjectName: { + Ref: 'ProjectC78D97AD', + }, + EnvironmentVariablesOverride: [ + { + Name: 'env', + Type: codebuild.BuildEnvironmentVariableType.PLAINTEXT, + Value: 'prod', + }, + ], + }, + }); +}); + +test('Task with env variables parameters using the deprecated ', () => { // WHEN const task = new CodeBuildStartBuild(stack, 'Task', { project: codebuildProject, @@ -100,6 +147,149 @@ test('Task with all the parameters', () => { }); }); +test('Task with additional parameters(source, cache, artifacts and so on).', () => { + const bucket = new s3.Bucket(stack, 'Bucket'); + // WHEN + const task = new CodeBuildStartBuild(stack, 'Task', { + project: codebuildProject, + integrationPattern: sfn.IntegrationPattern.RUN_JOB, + overrides: { + timeout: cdk.Duration.seconds(60*60), + source: codebuild.Source.gitHub({ + branchOrRef: 'my-commit-hash', + owner: 'aws', + repo: 'aws-cdk', + }), + environment: { + computeType: codebuild.ComputeType.LARGE, + }, + secondaryArtifacts: [ + codebuild.Artifacts.s3({ + bucket, + }), + ], + secondarySources: [ + codebuild.Source.gitHub({ + owner: 'aws', + repo: 'aws-cdk', + cloneDepth: 1, + branchOrRef: 'feature-branch', + identifier: 'source2', + }), + ], + }, + }); + + // THEN + expect(stack.resolve(task.toStateJson())).toEqual({ + Type: 'Task', + Resource: { + 'Fn::Join': [ + '', + [ + 'arn:', + { + Ref: 'AWS::Partition', + }, + ':states:::codebuild:startBuild.sync', + ], + ], + }, + End: true, + Parameters: { + ComputeTypeOverride: 'BUILD_GENERAL1_LARGE', + ProjectName: { + Ref: 'ProjectC78D97AD', + }, + ReportBuildStatusOverride: true, + SecondaryArtifactsOverride: [ + { + type: 'S3', + location: { + Ref: 'Bucket83908E77', + }, + namespaceType: 'BUILD_ID', + overrideArtifactName: true, + packaging: 'ZIP', + }, + ], + SecondarySourcesOverride: [ + { + gitCloneDepth: 1, + location: 'https://github.com/aws/aws-cdk.git', + reportBuildStatus: true, + type: 'GITHUB', + sourceIdentifier: 'source2', + }, + ], + SecondarySourcesVersionOverride: [ + { + sourceIdentifier: 'source2', + sourceVersion: 'feature-branch', + }, + ], + SourceLocationOverride: 'https://github.com/aws/aws-cdk.git', + SourceTypeOverride: 'GITHUB', + SourceVersion: 'my-commit-hash', + TimeoutInMinutesOverride: 60, + }, + }); +}); + +test('Task with illegal queuedTimeoutInMinutesOverride parameter', () => { + expect(() => { + new CodeBuildStartBuild(stack, 'Task', { + project: codebuildProject, + overrides: { + timeout: cdk.Duration.seconds(180), + }, + }); + }).toThrow( + /The value of override property "timeout" must be between 5 and 480 minutes./, + ); + + expect(() => { + new CodeBuildStartBuild(stack, 'Task2', { + project: codebuildProject, + overrides: { + timeout: cdk.Duration.hours(10), + }, + }); + }).toThrow( + /The value of override property "timeout" must be between 5 and 480 minutes./, + ); +}); + +test('Task with illegal ovriride secondaryArtifacts parameter', () => { + expect(() => { + const bucket = new s3.Bucket(stack, 'Bucket'); + new CodeBuildStartBuild(stack, 'Task', { + project: codebuildProject, + overrides: { + secondaryArtifacts: Array.apply(null, Array(13)).map((_x, _i) => codebuild.Artifacts.s3({ bucket, path: _i.toString() })), + }, + }); + }).toThrow( + /The maximum overrides that can be specified for 'secondaryArtifacts' is 12. Received: 13/, + ); +}); + +test('Task with illegal ovriride secondarySources parameter', () => { + expect(() => { + new CodeBuildStartBuild(stack, 'Task', { + project: codebuildProject, + overrides: { + secondarySources: Array.apply(null, Array(14)).map((_x, _i) => codebuild.Source.gitHub({ + owner: 'aws', + repo: 'aws-cdk', + })), + }, + }); + }).toThrow( + /The maximum overrides that can be specified for 'secondarySources' is 12. Received: 14/, + ); +}); + test('supports tokens', () => { // WHEN const task = new CodeBuildStartBuild(stack, 'Task', {