为自动回滚配置阶段 - AWS CodePipeline

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

为自动回滚配置阶段

您可以将管道中的阶段配置为在失败时自动回滚。当该阶段失败时,该阶段将回滚到最近一次成功执行的状态。只有在当前管道结构版本中启动之前的执行时,管道才能回滚到之前的执行。由于自动回滚配置是管道定义的一部分,因此只有在管道阶段成功执行管道之后,您的管道阶段才会自动回滚。

为自动回滚配置阶段(控制台)

您可以将阶段回滚到之前成功执行的指定阶段。有关更多信息,请参阅 CodePipeline API 指南RollbackStage中的。

为自动回滚配置阶段(控制台)
  1. 登录 AWS Management Console 并打开 CodePipeline 控制台,网址为 http://console.aws.amazon.com/codesuite/codepipeline/home

    将显示与您的 AWS 账户关联的所有管道的名称和状态。

  2. Name 中,选择您要编辑的管道的名称。

  3. 在管道详细信息页中,选择编辑

  4. “编辑” 页面上,对于要编辑的操作,选择 “编辑阶段”

  5. 选择 “配置舞台失败时自动回滚”。将更改保存到您的管道中。

    用于配置回滚阶段的编辑屏幕示例 CodePipeline。

为自动回滚配置阶段 (CLI)

要使用 AWS CLI 将失败阶段配置为自动回滚到最近一次成功执行的阶段,请使用命令创建或更新管道,详见在中创建管道 CodePipeline和中在中编辑管道 CodePipeline

  • 打开终端(Linux、macOS 或 Unix)或命令提示符 (Windows),然后使用运行update-pipeline命令,在管道结构中指定失败条件。 AWS CLI 以下示例为名为的分阶段配置自动回滚:S3Deploy

    { "name": "S3Deploy", "actions": [ { "name": "s3deployaction", "actionTypeId": { "category": "Deploy", "owner": "AWS", "provider": "S3", "version": "1" }, "runOrder": 1, "configuration": { "BucketName": "static-website-bucket", "Extract": "false", "ObjectKey": "SampleApp.zip" }, "outputArtifacts": [], "inputArtifacts": [ { "name": "SourceArtifact" } ], "region": "us-east-1" } ], "onFailure": { "result": "ROLLBACK" } }

    有关为阶段回滚配置故障条件的更多信息,请参阅 CodePipeline API 参考FailureConditions中的。

为自动回滚配置阶段 ()AWS CloudFormation

AWS CloudFormation 要使用将舞台配置为在失败时自动回滚,请使用OnFailure参数。失败时,该阶段将自动回滚到最近的成功执行。

OnFailure: Result: ROLLBACK
  • 更新模板,如以下代码段所示。以下示例为名为的分阶段配置自动回滚:Release

    AppPipeline: Type: AWS::CodePipeline::Pipeline Properties: RoleArn: Ref: CodePipelineServiceRole Stages: - Name: Source Actions: - Name: SourceAction ActionTypeId: Category: Source Owner: AWS Version: 1 Provider: S3 OutputArtifacts: - Name: SourceOutput Configuration: S3Bucket: Ref: SourceS3Bucket S3ObjectKey: Ref: SourceS3ObjectKey RunOrder: 1 - Name: Release Actions: - Name: ReleaseAction InputArtifacts: - Name: SourceOutput ActionTypeId: Category: Deploy Owner: AWS Version: 1 Provider: CodeDeploy Configuration: ApplicationName: Ref: ApplicationName DeploymentGroupName: Ref: DeploymentGroupName RunOrder: 1 OnFailure: Result: ROLLBACK ArtifactStore: Type: S3 Location: Ref: ArtifactStoreS3Location EncryptionKey: Id: arn:aws:kms:useast-1:ACCOUNT-ID:key/KEY-ID Type: KMS DisableInboundStageTransitions: - StageName: Release Reason: "Disabling the transition until integration tests are completed" Tags: - Key: Project Value: ProjectA - Key: IsContainerBased Value: 'true'

    有关为阶段回滚配置故障条件的更多信息,请参阅OnFailureAWS CloudFormation 用户指南StageDeclaration中的。