Manage (管理) AWS CodeBuild 使用 Step Functions 構建 - AWS Step Functions

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

Manage (管理) AWS CodeBuild 使用 Step Functions 構建

您可以將 Step Functions 與 AWS CodeBuild 以啟動、停止和管理組建。此頁面列出了 CodeBuild APIs可與 Step Functions 搭配使用的支援項目。

若要瞭解如何整合 AWS 服務在 Step Functions 中,請參閱整合 服務和。將參數傳遞給 Step Functions 數API中的服務

與 Step Functions 集成 AWS CodeBuild 您可以使用 Step Functions 觸發、停止和管理組建,以及共用組建報告。使用 Step Functions,您可以設計並執行持續整合管道,以驗證應用程式的軟體變更。

最佳化 CodeBuild 整合的主要功能
  • 支援執行任務 (.sync)整合模式。

  • 在您呼叫StopBuild或之後StopBuildBatch,建置或建置批次不會立即刪除,直到某些內部工作完成以完成建置或組建的狀態 CodeBuild 為止。

    如果您嘗試使用BatchDeleteBuildsDeleteBuildBatch在此期間,可能不會刪除組建或建置批次。

    優化的服務集成,BatchDeleteBuildsDeleteBuildBatch包括內部重試,以簡化停止後立即刪除的用例。

並非所有的整合模式都APIs支援所有的整合模式,如下表所示。

API 請求回應 執行任務 (.sync)
StartBuild 支援 支援
StopBuild 支援 不支援
BatchDeleteBuilds 支援 不支援
BatchGetReports 支援 不支援
StartBuildBatch 支援 支援
StopBuildBatch 支援 不支援
RetryBuildBatch 支援 支援
DeleteBuildBatch 支援 不支援
中的參數 Step Functions 表示於 PascalCase

即使原生服務位API於中 camelCase (例如API動作)startSyncExecution,您也可以在中指定參數 PascalCase,例如:StateMachineArn

支援 CodeBuild APIs

注意

您可以使用 JSONPath 遞歸下降適用於 BatchDeleteBuilds 的 (..) 運算子。使用傳回的陣列,您可以將Arn欄位從轉換StartBuild成複Ids數參數,如下列範例所示。

"BatchDeleteBuilds": { "Type": "Task", "Resource": "arn:aws:states:::codebuild:batchDeleteBuilds", "Parameters": { "Ids.$": "$.Build..Arn" }, "Next": "MyNextState" },

IAM呼叫的原則 AWS CodeBuild

下面的示例模板顯示如何 AWS Step Functions 根據狀態機器定義中的資源產生IAM策略。如需詳細資訊,請參閱 Step Functions 式如何為整合式服務產生IAM原則探索 Step Functions 中的服務整合模式

資源:

{ "Version": "2012-10-17", "Statement": [ { "Action": [ "sns:Publish" ], "Resource": [ "arn:aws:sns:sa-east-1:123456789012:StepFunctionsSample-CodeBuildExecution1111-2222-3333-wJalrXUtnFEMI-SNSTopic-bPxRfiCYEXAMPLEKEY" ], "Effect": "Allow" }, { "Action": [ "codebuild:StartBuild", "codebuild:StopBuild", "codebuild:BatchGetBuilds", "codebuild:BatchGetReports" ], "Resource": "*", "Effect": "Allow" }, { "Action": [ "events:PutTargets", "events:PutRule", "events:DescribeRule" ], "Resource": [ "arn:aws:events:sa-east-1:123456789012:rule/StepFunctionsGetEventForCodeBuildStartBuildRule" ], "Effect": "Allow" } ] }

StartBuild

靜態資源

Run a Job (.sync)
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:StartBuild", "codebuild:StopBuild", "codebuild:BatchGetBuilds" ], "Resource": [ "arn:aws:codebuild:[[region]]:[[accountId]]:project/[[projectName]]" ] }, { "Effect": "Allow", "Action": [ "events:PutTargets", "events:PutRule", "events:DescribeRule" ], "Resource": [ "arn:aws:events:[[region]]:[[accountId]]:rule/StepFunctionsGetEventForCodeBuildStartBuildRule" ] } ] }
Request Response
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:StartBuild" ], "Resource": [ "arn:aws:codebuild:[[region]]:[[accountId]]:project/[[projectName]]" ] } ] }

動態資源

Run a Job (.sync)
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:StartBuild", "codebuild:StopBuild", "codebuild:BatchGetBuilds" ], "Resource": [ "arn:aws:codebuild:[[region]]:*:project/*" ] }, { "Effect": "Allow", "Action": [ "events:PutTargets", "events:PutRule", "events:DescribeRule" ], "Resource": [ "arn:aws:events:[[region]]:[[accountId]]:rule/StepFunctionsGetEventForCodeBuildStartBuildRule" ] } ] }
Request Response
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:StartBuild" ], "Resource": [ "arn:aws:codebuild:[[region]]:*:project/*" ] } ] }

StopBuild

靜態資源

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:StopBuild" ], "Resource": [ "arn:aws:codebuild:[[region]]:[[accountId]]:project/[[projectName]]" ] } ] }

動態資源

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:StopBuild" ], "Resource": [ "arn:aws:codebuild:[[region]]:*:project/*" ] } ] }

BatchDeleteBuilds

靜態資源

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:BatchDeleteBuilds" ], "Resource": [ "arn:aws:codebuild:[[region]]:[[accountId]]:project/[[projectName]]" ] } ] }

動態資源

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:BatchDeleteBuilds" ], "Resource": [ "arn:aws:codebuild:[[region]]:*:project/*" ] } ] }

BatchGetReports

靜態資源

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:BatchGetReports" ], "Resource": [ "arn:aws:codebuild:[[region]]:[[accountId]]:report-group/[[reportName]]" ] } ] }

動態資源

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:BatchGetReports" ], "Resource": [ "arn:aws:codebuild:[[region]]:*:report-group/*" ] } ] }

StartBuildBatch

靜態資源

Run a Job (.sync)
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:StartBuildBatch", "codebuild:StopBuildBatch", "codebuild:BatchGetBuildBatches" ], "Resource": [ "arn:aws:codebuild:[[region]]:[[accountId]]:project/[[projectName]]" ] }, { "Effect": "Allow", "Action": [ "events:PutTargets", "events:PutRule", "events:DescribeRule" ], "Resource": [ "arn:aws:events:[[region]]:[[accountId]]:rule/StepFunctionsGetEventForCodeBuildStartBuildBatchRule" ] } ] }
Request Response
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:StartBuildBatch" ], "Resource": [ "arn:aws:codebuild:[[region]]:[[accountId]]:project/[[projectName]]" ] } ] }

動態資源

Run a Job (.sync)
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:StartBuildBatch", "codebuild:StopBuildBatch", "codebuild:BatchGetBuildBatches" ], "Resource": [ "arn:aws:codebuild:[[region]]:[[accountId]]:project/*" ] }, { "Effect": "Allow", "Action": [ "events:PutTargets", "events:PutRule", "events:DescribeRule" ], "Resource": [ "arn:aws:events:[[region]]:[[accountId]]:rule/StepFunctionsGetEventForCodeBuildStartBuildBatchRule" ] } ] }
Request Response
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:StartBuildBatch" ], "Resource": [ "arn:aws:codebuild:[[region]]:[[accountId]]:project/*" ] } ] }

StopBuildBatch

靜態資源

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:StopBuildBatch" ], "Resource": [ "arn:aws:codebuild:[[region]]:[[accountId]]:project/[[projectName]]" ] } ] }

動態資源

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:StopBuildBatch" ], "Resource": [ "arn:aws:codebuild:[[region]]:[[accountId]]:project/*" ] } ] }

RetryBuildBatch

靜態資源

Run a Job (.sync)
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:RetryBuildBatch", "codebuild:StopBuildBatch", "codebuild:BatchGetBuildBatches" ], "Resource": [ "arn:aws:codebuild:[[region]]:[[accountId]]:project/[[projectName]]" ] } ] }
Request Response
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:RetryBuildBatch" ], "Resource": [ "arn:aws:codebuild:[[region]]:[[accountId]]:project/[[projectName]]" ] } ] }

動態資源

Run a Job (.sync)
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:RetryBuildBatch", "codebuild:StopBuildBatch", "codebuild:BatchGetBuildBatches" ], "Resource": [ "arn:aws:codebuild:[[region]]:[[accountId]]:project/*" ] } ] }
Request Response
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:RetryBuildBatch" ], "Resource": [ "arn:aws:codebuild:[[region]]:[[accountId]]:project/*" ] } ] }

DeleteBuildBatch

靜態資源

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:DeleteBuildBatch" ], "Resource": [ "arn:aws:codebuild:[[region]]:[[accountId]]:project/[[projectName]]" ] } ] }

動態資源

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codebuild:DeleteBuildBatch" ], "Resource": [ "arn:aws:codebuild:[[region]]:[[accountId]]:project/*" ] } ] }