本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
您可以設定管道中的階段,以在失敗時自動復原。當階段失敗時,階段會復原至最近成功的執行。只有在目前的管道結構版本中啟動先前的執行時,管道才能復原至先前的執行。由於自動轉返組態是管道定義的一部分,因此只有在管道階段成功執行管道之後,您的管道階段才會自動轉返。
設定自動轉返的階段 (主控台)
您可以將階段復原至先前成功的指定執行。如需詳細資訊,請參閱 CodePipeline API 指南中的 RollbackStage。
設定自動轉返的階段 (主控台)
登入 AWS Management Console 並開啟 CodePipeline 主控台,網址為 https://http://console.aws.amazon.com/codesuite/codepipeline/home
。 與 AWS 您的帳戶相關聯的所有管道名稱和狀態都會顯示。
-
在 Name (名稱) 中,選擇您想編輯的管道名稱。
-
在管道詳細資訊頁面上,選擇 Edit (編輯)。
-
在編輯頁面上,針對您要編輯的動作,選擇編輯階段。
-
選擇自動化階段組態:,然後選擇在階段失敗時設定自動轉返。將變更儲存至您的管道。
設定自動轉返的階段 (CLI)
若要使用 AWS CLI 將失敗的階段設定為自動復原至最近的成功執行,請使用 命令來建立或更新管道,如 建立管道、階段和動作和 中所述在 CodePipeline 中編輯管道。
-
開啟終端機 (Linux、macOS 或 Unix) 或命令提示字元 AWS CLI (Windows),然後使用 執行
update-pipeline
命令,在管道結構中指定失敗條件。下列範例會為名為 的階段設定自動轉返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'
如需設定階段復原失敗條件的詳細資訊,請參閱AWS CloudFormation 《 使用者指南》
StageDeclaration
中的 OnFailure。