diff --git a/packages/@aws-cdk/pipelines/README.md b/packages/@aws-cdk/pipelines/README.md index b575fcd00732d..238fa51dbc710 100644 --- a/packages/@aws-cdk/pipelines/README.md +++ b/packages/@aws-cdk/pipelines/README.md @@ -362,7 +362,8 @@ stage.addActions(new ShellScriptAction({ vpc, // Optionally specify SecurityGroups securityGroups, - // ... more configuration ... + // Optionally specify a BuildEnvironment + environment, })); ``` 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 4fb610688e9a4..1b439fe309c7e 100644 --- a/packages/@aws-cdk/pipelines/lib/validation/shell-script-action.ts +++ b/packages/@aws-cdk/pipelines/lib/validation/shell-script-action.ts @@ -54,6 +54,13 @@ export interface ShellScriptActionProps { */ readonly additionalArtifacts?: codepipeline.Artifact[]; + /** + * The CodeBuild environment where scripts are executed. + * + * @default LinuxBuildImage.STANDARD_4_0 + */ + readonly environment?: codebuild.BuildEnvironment + /** * RunOrder for this action * @@ -177,7 +184,7 @@ export class ShellScriptAction implements codepipeline.IAction, iam.IGrantable { } this._project = new codebuild.PipelineProject(scope, 'Project', { - environment: { buildImage: codebuild.LinuxBuildImage.STANDARD_4_0 }, + environment: this.props.environment || { buildImage: codebuild.LinuxBuildImage.STANDARD_4_0 }, vpc: this.props.vpc, securityGroups: this.props.securityGroups, subnetSelection: this.props.subnetSelection, diff --git a/packages/@aws-cdk/pipelines/test/validation.test.ts b/packages/@aws-cdk/pipelines/test/validation.test.ts index 9986aad4d2758..4f1cffbef61ec 100644 --- a/packages/@aws-cdk/pipelines/test/validation.test.ts +++ b/packages/@aws-cdk/pipelines/test/validation.test.ts @@ -1,5 +1,6 @@ import { anything, arrayWith, deepObjectLike, encodedJson } from '@aws-cdk/assert'; import '@aws-cdk/assert/jest'; +import * as codebuild from '@aws-cdk/aws-codebuild'; import * as codepipeline from '@aws-cdk/aws-codepipeline'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as iam from '@aws-cdk/aws-iam'; @@ -330,6 +331,64 @@ test('run ShellScriptAction with Security Group', () => { }); }); +test('run ShellScriptAction with specified codebuild image', () => { + // WHEN + pipeline.addStage('Test').addActions(new cdkp.ShellScriptAction({ + actionName: 'imageAction', + additionalArtifacts: [integTestArtifact], + commands: ['true'], + environment: { buildImage: codebuild.LinuxBuildImage.STANDARD_2_0 }, + })); + + // THEN + expect(pipelineStack).toHaveResourceLike('AWS::CodePipeline::Pipeline', { + Stages: arrayWith({ + Name: 'Test', + Actions: [ + deepObjectLike({ + Name: 'imageAction', + }), + ], + }), + }); + expect(pipelineStack).toHaveResourceLike('AWS::CodeBuild::Project', { + Environment: { + 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', + }, + ], + }, + }); +}); + class AppWithStackOutput extends Stage { public readonly output: CfnOutput;