StartBuild 搭配 a AWS SDK 或 CLI 使用 - AWS SDK 程式碼範例

文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的 GitHub 範例。

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

StartBuild 搭配 a AWS SDK 或 CLI 使用

下列程式碼範例示範如何使用 StartBuild

C++
C++ 的 SDK
注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

//! Start an AWS CodeBuild project build. /*! \param projectName: A CodeBuild project name. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::CodeBuild::startBuild(const Aws::String &projectName, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::CodeBuild::CodeBuildClient codeBuildClient(clientConfiguration); Aws::CodeBuild::Model::StartBuildRequest startBuildRequest; startBuildRequest.SetProjectName(projectName); Aws::CodeBuild::Model::StartBuildOutcome outcome = codeBuildClient.StartBuild( startBuildRequest); if (outcome.IsSuccess()) { std::cout << "Successfully started build" << std::endl; std::cout << "Build ID: " << outcome.GetResult().GetBuild().GetId() << std::endl; } else { std::cerr << "Error starting build" << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
  • 如需 API 詳細資訊,請參閱 StartBuild AWS SDK for C++ 參考中的 API

CLI
AWS CLI

開始執行建置 a AWS CodeBuild 建置專案。

下列start-build範例會啟動指定 CodeBuild 專案的建置。建置會覆寫專案的設定,以允許在建置逾時前佇列的分鐘數,以及專案的成品設定。

aws codebuild start-build \ --project-name "my-demo-project" \ --queued-timeout-in-minutes-override 5 \ --artifacts-override {"\"type\": \"S3\",\"location\": \"arn:aws:s3:::artifacts-override\",\"overrideArtifactName\":true"}

輸出:

{ "build": { "serviceRole": "arn:aws:iam::123456789012:role/service-role/my-codebuild-service-role", "buildStatus": "IN_PROGRESS", "buildComplete": false, "projectName": "my-demo-project", "timeoutInMinutes": 60, "source": { "insecureSsl": false, "type": "S3", "location": "codebuild-us-west-2-123456789012-input-bucket/my-source.zip" }, "queuedTimeoutInMinutes": 5, "encryptionKey": "arn:aws:kms:us-west-2:123456789012:alias/aws/s3", "currentPhase": "QUEUED", "startTime": 1556905683.568, "environment": { "computeType": "BUILD_GENERAL1_MEDIUM", "environmentVariables": [], "type": "LINUX_CONTAINER", "privilegedMode": false, "image": "aws/codebuild/standard:1.0", "imagePullCredentialsType": "CODEBUILD" }, "phases": [ { "phaseStatus": "SUCCEEDED", "startTime": 1556905683.568, "phaseType": "SUBMITTED", "durationInSeconds": 0, "endTime": 1556905684.524 }, { "startTime": 1556905684.524, "phaseType": "QUEUED" } ], "logs": { "deepLink": "https://console.aws.amazon.com/cloudwatch/home?region=us-west-2#logEvent:group=null;stream=null" }, "artifacts": { "encryptionDisabled": false, "location": "arn:aws:s3:::artifacts-override/my-demo-project", "overrideArtifactName": true }, "cache": { "type": "NO_CACHE" }, "id": "my-demo-project::12345678-a1b2-c3d4-e5f6-11111EXAMPLE", "initiator": "my-aws-account-name", "arn": "arn:aws:codebuild:us-west-2:123456789012:build/my-demo-project::12345678-a1b2-c3d4-e5f6-11111EXAMPLE" } }

如需詳細資訊,請參閱 AWS CLI 使用者指南中的執行建置 (Word)AWS CodeBuild

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 StartBuild