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

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

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

与 AWS SDK或ListBuilds一起使用 CLI

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

C++
SDK对于 C++
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

//! List the CodeBuild builds. /*! \param sortType: 'SortOrderType' type. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::CodeBuild::listBuilds(Aws::CodeBuild::Model::SortOrderType sortType, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::CodeBuild::CodeBuildClient codeBuildClient(clientConfiguration); Aws::CodeBuild::Model::ListBuildsRequest listBuildsRequest; listBuildsRequest.SetSortOrder(sortType); Aws::String nextToken; // Used for pagination. do { if (!nextToken.empty()) { listBuildsRequest.SetNextToken(nextToken); } Aws::CodeBuild::Model::ListBuildsOutcome listBuildsOutcome = codeBuildClient.ListBuilds( listBuildsRequest); if (listBuildsOutcome.IsSuccess()) { const Aws::Vector<Aws::String> &ids = listBuildsOutcome.GetResult().GetIds(); if (!ids.empty()) { std::cout << "Information about each build:" << std::endl; Aws::CodeBuild::Model::BatchGetBuildsRequest getBuildsRequest; getBuildsRequest.SetIds(listBuildsOutcome.GetResult().GetIds()); Aws::CodeBuild::Model::BatchGetBuildsOutcome getBuildsOutcome = codeBuildClient.BatchGetBuilds( getBuildsRequest); if (getBuildsOutcome.IsSuccess()) { const Aws::Vector<Aws::CodeBuild::Model::Build> &builds = getBuildsOutcome.GetResult().GetBuilds(); std::cout << builds.size() << " build(s) found." << std::endl; for (auto val: builds) { std::cout << val.GetId() << std::endl; } } else { std::cerr << "Error getting builds" << getBuildsOutcome.GetError().GetMessage() << std::endl; return false; } } else { std::cout << "No builds found." << std::endl; } // Get the next token for pagination. nextToken = listBuildsOutcome.GetResult().GetNextToken(); } else { std::cerr << "Error listing builds" << listBuildsOutcome.GetError().GetMessage() << std::endl; return false; } } while (!nextToken. empty() ); return true; }
  • 有关API详细信息,请参阅 “AWS SDK for C++ API参考 ListBuilds” 中的。

CLI
AWS CLI

获取 AWS CodeBuild 版本列表IDs。

以下list-builds示例获取按升 CodeBuild IDs序排序的列表。

aws codebuild list-builds --sort-order ASCENDING

输出包含一个nextToken值,该值表示还有更多可用的输出。

{ "nextToken": "4AEA6u7J...The full token has been omitted for brevity...MzY2OA==", "ids": [ "codebuild-demo-project:815e755f-bade-4a7e-80f0-efe51EXAMPLE" "codebuild-demo-project:84a7f3d1-d40e-4956-b4cf-7a9d4EXAMPLE" ... The full list of build IDs has been omitted for brevity ... "codebuild-demo-project:931d0b72-bf6f-4040-a472-5c707EXAMPLE" ] }

再次运行此命令并提供上一个响应中的nextToken值作为参数,以获取输出的下一部分。重复此操作,直到您在响应中没有收到任何nextToken值。

aws codebuild list-builds --sort-order ASCENDING --next-token 4AEA6u7J...The full token has been omitted for brevity...MzY2OA==

输出的下一部分:

{ "ids": [ "codebuild-demo-project:49015049-21cf-4b50-9708-df115EXAMPLE", "codebuild-demo-project:543e7206-68a3-46d6-a4da-759abEXAMPLE", ... The full list of build IDs has been omitted for brevity ... "codebuild-demo-project:c282f198-4582-4b38-bdc0-26f96EXAMPLE" ] }

有关更多信息,请参阅《AWS CodeBuild 用户指南》中的查看 Build IDs (AWS CLI) 列表