Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pipelines): ShellScriptAction can configure environment #11229

Merged
merged 9 commits into from
Nov 9, 2020
3 changes: 2 additions & 1 deletion packages/@aws-cdk/pipelines/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ stage.addActions(new ShellScriptAction({
vpc,
// Optionally specify SecurityGroups
securityGroups,
// ... more configuration ...
// Optionally specify a BuildEnvironment
environment,
}));
```

Expand Down
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 environment where scripts are executed.
*
* @default LinuxBuildImage.STANDARD_4_0
*/
readonly environment?: codebuild.BuildEnvironment

/**
* 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: this.props.environment || { buildImage: codebuild.LinuxBuildImage.STANDARD_4_0 },
vpc: this.props.vpc,
securityGroups: this.props.securityGroups,
subnetSelection: this.props.subnetSelection,
Expand Down
59 changes: 59 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,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;

Expand Down