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(codepipeline): executionMode property for Pipeline #29148

Merged
merged 10 commits into from
Mar 8, 2024
35 changes: 35 additions & 0 deletions packages/aws-cdk-lib/aws-codepipeline/lib/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,24 @@ export enum PipelineType {
V2 = 'V2',
}

/**
* Execution mode.
*/
export enum ExecutionMode {
/**
* QUEUED mode
go-to-k marked this conversation as resolved.
Show resolved Hide resolved
*/
QUEUED = 'QUEUED',
/**
* SUPERSEDED mode
go-to-k marked this conversation as resolved.
Show resolved Hide resolved
*/
SUPERSEDED = 'SUPERSEDED',
/**
* PARALLEL mode
go-to-k marked this conversation as resolved.
Show resolved Hide resolved
*/
PARALLEL = 'PARALLEL',
}

export interface PipelineProps {
/**
* The S3 bucket used by this Pipeline to store artifacts.
Expand Down Expand Up @@ -224,6 +242,14 @@ export interface PipelineProps {
* @default - No triggers
*/
readonly triggers?: TriggerProps[];

/**
* The method that the pipeline will use to handle multiple executions.
*
* @default - ExecutionMode.SUPERSEDED
*/
readonly executionMode?: ExecutionMode;

}

abstract class PipelineBase extends Resource implements IPipeline {
Expand Down Expand Up @@ -495,6 +521,14 @@ export class Pipeline extends PipelineBase {
}
this.pipelineType = props.pipelineType ?? PipelineType.V1;

if (
props.executionMode
&& [ExecutionMode.QUEUED, ExecutionMode.PARALLEL].includes(props.executionMode)
&& this.pipelineType !== PipelineType.V2
) {
throw new Error(`${props.executionMode} execution mode can only be used with V2 pipelines, \`PipelineType.V2\` must be specified for \`pipelineType\``);
}

Comment on lines +537 to +544
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have confirmed that the error occurs when QUEUED or PARALLEL mode is specified in the AWS console.

QUEUED or PARALLEL mode can only be used with V2 pipelines

this.codePipeline = new CfnPipeline(this, 'Resource', {
artifactStore: Lazy.any({ produce: () => this.renderArtifactStoreProperty() }),
artifactStores: Lazy.any({ produce: () => this.renderArtifactStoresProperty() }),
Expand All @@ -505,6 +539,7 @@ export class Pipeline extends PipelineBase {
pipelineType: props.pipelineType,
variables: Lazy.any({ produce: () => this.renderVariables() }, { omitEmptyArray: true }),
triggers: Lazy.any({ produce: () => this.renderTriggers() }, { omitEmptyArray: true }),
executionMode: props.executionMode,
name: this.physicalName,
});

Expand Down
51 changes: 51 additions & 0 deletions packages/aws-cdk-lib/aws-codepipeline/test/pipeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,57 @@ describe('', () => {
PipelineType: expected,
});
});

test.each([
[codepipeline.ExecutionMode.SUPERSEDED, 'SUPERSEDED'],
[codepipeline.ExecutionMode.QUEUED, 'QUEUED'],
[codepipeline.ExecutionMode.PARALLEL, 'PARALLEL'],
])('can specify execution mode %s', (type, expected) => {
const stack = new cdk.Stack();
const pipeline = new codepipeline.Pipeline(stack, 'Pipeline', {
pipelineType: codepipeline.PipelineType.V2,
executionMode: type,
});

const sourceArtifact = new codepipeline.Artifact();
const sourceActions = [new FakeSourceAction({
actionName: 'FakeSource',
output: sourceArtifact,
})];
const buildActions = [new FakeBuildAction({
actionName: 'FakeBuild',
input: sourceArtifact,
})];
testPipelineSetup(pipeline, sourceActions, buildActions);

Template.fromStack(stack).hasResourceProperties('AWS::CodePipeline::Pipeline', {
ExecutionMode: expected,
});
});

test('throws if executionMode is QUEUED but pipeline type is not V2', () => {
const app = new cdk.App();
const stack = new cdk.Stack(app, 'PipelineStack');

expect(() => {
new codepipeline.Pipeline(stack, 'Pipeline', {
pipelineType: codepipeline.PipelineType.V1,
executionMode: codepipeline.ExecutionMode.QUEUED,
});
}).toThrow('QUEUED execution mode can only be used with V2 pipelines, `PipelineType.V2` must be specified for `pipelineType`');
});

test('throws if executionMode is PARALLEL but pipeline type is not V2', () => {
const app = new cdk.App();
const stack = new cdk.Stack(app, 'PipelineStack');

expect(() => {
new codepipeline.Pipeline(stack, 'Pipeline', {
pipelineType: codepipeline.PipelineType.V1,
executionMode: codepipeline.ExecutionMode.PARALLEL,
});
}).toThrow('PARALLEL execution mode can only be used with V2 pipelines, `PipelineType.V2` must be specified for `pipelineType`');
});
});

describe('cross account key alias name tests', () => {
Expand Down
Loading