与 AWS SDK或StartBuild一起使用 CLI - AWS SDK代码示例

AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例

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

与 AWS SDK或StartBuild一起使用 CLI

以下代码示例演示如何使用 StartBuild

C++
SDK对于 C++
注意

还有更多相关信息 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详细信息,请参阅 “AWS SDK for C++ API参考 StartBuild” 中的。

CLI
AWS CLI

开始运行 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 CodeBuild 用户指南》中的 “运行构建” (AWS CLI)