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): auto rollback for pipeline #30465

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions packages/aws-cdk-lib/aws-codepipeline/lib/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ export interface StagePlacement {
readonly justAfter?: IStage;
}

/**
* Result type for failure conditions.
*/
export enum FailureConditionsResult {
/**
* ROLLBACK
*/
ROLLBACK = 'ROLLBACK',
}

/**
* Failure conditions for Stage props.
*/
export interface FailureConditions {
/**
* The specified result for when the failure conditions are met,
* such as rolling back the stage.
*
* @default ROLLBACK
*/
readonly result?: FailureConditionsResult;
}

/**
* Construction properties of a Pipeline Stage.
*/
Expand Down Expand Up @@ -89,6 +112,16 @@ export interface StageProps {
* @default 'Transition disabled'
*/
readonly transitionDisabledReason?: string;

/**
* The method to use when a stage has not completed successfully.
*
* For example, configuring this field for rollback will roll back a failed
* stage automatically to the last successful pipeline execution in the stage.
*
* @default - No failure conditions.
*/
readonly onFailure?: FailureConditions;
}

export interface StageOptions extends StageProps {
Expand Down
7 changes: 6 additions & 1 deletion packages/aws-cdk-lib/aws-codepipeline/lib/private/stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Token } from '../../../core';
import { IAction, IPipeline, IStage } from '../action';
import { Artifact } from '../artifact';
import { CfnPipeline } from '../codepipeline.generated';
import { Pipeline, StageProps } from '../pipeline';
import { FailureConditions, FailureConditionsResult, Pipeline, StageProps } from '../pipeline';

/**
* A Stage in a Pipeline.
Expand All @@ -27,6 +27,7 @@ export class Stage implements IStage {
private readonly scope: Construct;
private readonly _pipeline: Pipeline;
private readonly _actions = new Array<FullActionDescriptor>();
private readonly _onFailure?: FailureConditions;

/**
* Create a new Stage.
Expand All @@ -39,6 +40,7 @@ export class Stage implements IStage {
this.transitionDisabledReason = props.transitionDisabledReason ?? 'Transition disabled';
this._pipeline = pipeline;
this.scope = new Construct(pipeline, this.stageName);
this._onFailure = props.onFailure;

for (const action of props.actions || []) {
this.addAction(action);
Expand Down Expand Up @@ -81,6 +83,9 @@ export class Stage implements IStage {
return {
name: this.stageName,
actions: this._actions.map(action => this.renderAction(action)),
onFailure: this._onFailure ? {
result: this._onFailure?.result ?? FailureConditionsResult.ROLLBACK,
} : undefined,
};
}

Expand Down
Loading