Skip to content

Commit

Permalink
fix(pipelines) allow specification of buildImage in ShellScriptAction
Browse files Browse the repository at this point in the history
The codebuild image of the ShellScriptAction was hardcoded. Some validation scripts require a different codebuild image.
This commit adds a property to the ShellScriptAction class to specify the image, which defaults to linux_4_0 (the current hardcoded value).
fixes aws#10919
  • Loading branch information
tdikland committed Oct 30, 2020
1 parent 1097ec0 commit 7db98c6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ export interface ShellScriptActionProps {
*/
readonly additionalArtifacts?: codepipeline.Artifact[];

/**
* The CodeBuild image used for the build.
*
* @default LinuxBuildImage.STANDARD_4_0
*/
readonly buildImage?: codebuild.IBuildImage

/**
* RunOrder for this action
*
Expand Down Expand Up @@ -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: { buildImage: this.props.buildImage || codebuild.LinuxBuildImage.STANDARD_4_0 },
vpc: this.props.vpc,
securityGroups: this.props.securityGroups,
subnetSelection: this.props.subnetSelection,
Expand Down
28 changes: 28 additions & 0 deletions packages/@aws-cdk/pipelines/test/validation.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -330,6 +331,33 @@ 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'],
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',
},
});
});

class AppWithStackOutput extends Stage {
public readonly output: CfnOutput;

Expand Down

0 comments on commit 7db98c6

Please sign in to comment.