From bf24aad16808757236f38af752b49f2707130fb8 Mon Sep 17 00:00:00 2001 From: tdikland Date: Fri, 30 Oct 2020 21:48:48 +0000 Subject: [PATCH] feat(pipelines) ShellScriptAction add option to configure codebuild environment The build environment for the ShellScriptAction is hardcoded and set to LINUX_4_0. This fix allows the build environment to be specified in the ShellScriptAction fixes #10919 --- .../lib/validation/shell-script-action.ts | 2 +- .../pipelines/test/validation.test.ts | 35 +++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/pipelines/lib/validation/shell-script-action.ts b/packages/@aws-cdk/pipelines/lib/validation/shell-script-action.ts index d3ac743f65bc7..1b439fe309c7e 100644 --- a/packages/@aws-cdk/pipelines/lib/validation/shell-script-action.ts +++ b/packages/@aws-cdk/pipelines/lib/validation/shell-script-action.ts @@ -55,7 +55,7 @@ export interface ShellScriptActionProps { readonly additionalArtifacts?: codepipeline.Artifact[]; /** - * The CodeBuild image used for the build. + * The CodeBuild environment where scripts are executed. * * @default LinuxBuildImage.STANDARD_4_0 */ diff --git a/packages/@aws-cdk/pipelines/test/validation.test.ts b/packages/@aws-cdk/pipelines/test/validation.test.ts index 81328a584139c..4f1cffbef61ec 100644 --- a/packages/@aws-cdk/pipelines/test/validation.test.ts +++ b/packages/@aws-cdk/pipelines/test/validation.test.ts @@ -337,7 +337,7 @@ test('run ShellScriptAction with specified codebuild image', () => { actionName: 'imageAction', additionalArtifacts: [integTestArtifact], commands: ['true'], - buildImage: codebuild.LinuxBuildImage.STANDARD_2_0, + environment: { buildImage: codebuild.LinuxBuildImage.STANDARD_2_0 }, })); // THEN @@ -353,7 +353,38 @@ test('run ShellScriptAction with specified codebuild image', () => { }); expect(pipelineStack).toHaveResourceLike('AWS::CodeBuild::Project', { Environment: { - Image: 'aws/codebuild/standard:5.0', + Image: 'aws/codebuild/standard:2.0', + }, + }); +}); + +test('run ShellScriptAction with specified BuildEnvironment', () => { + // WHEN + pipeline.addStage('Test').addActions(new cdkp.ShellScriptAction({ + actionName: 'imageAction', + additionalArtifacts: [integTestArtifact], + commands: ['true'], + environment: { + buildImage: codebuild.LinuxBuildImage.STANDARD_2_0, + computeType: codebuild.ComputeType.LARGE, + environmentVariables: { FOO: { value: 'BAR', type: codebuild.BuildEnvironmentVariableType.PLAINTEXT } }, + privileged: true, + }, + })); + + // THEN + expect(pipelineStack).toHaveResourceLike('AWS::CodeBuild::Project', { + Environment: { + Image: 'aws/codebuild/standard:2.0', + PrivilegedMode: true, + ComputeType: 'BUILD_GENERAL1_LARGE', + EnvironmentVariables: [ + { + Type: 'PLAINTEXT', + Value: 'BAR', + Name: 'FOO', + }, + ], }, }); });