There are more AWS SDK examples available in the AWS Doc SDK Examples
Use ListBuilds
with an AWS SDK or CLI
The following code examples show how to use ListBuilds
.
- C++
-
- SDK for C++
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. //! 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; }
-
For API details, see ListBuilds in AWS SDK for C++ API Reference.
-
- CLI
-
- AWS CLI
-
To get a list of AWS CodeBuild builds IDs.
The following
list-builds
example gets a list of CodeBuild IDs sorted in ascending order.aws codebuild list-builds --sort-order
ASCENDING
The output includes a
nextToken
value which indicates that there is more output available.{ "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" ] }
Run this command again and provide the
nextToken
value in the previous response as a parameter to get the next part of the output. Repeat until you don't receive anextToken
value in the response.aws codebuild list-builds --sort-order
ASCENDING
--next-token4AEA6u7J...The
full
token
has
been
omitted
for
brevity...MzY2OA==
Next part of the output:
{ "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" ] }
For more information, see View a List of Build IDs (AWS CLI) in the AWS CodeBuild User Guide
-
For API details, see ListBuilds
in AWS CLI Command Reference.
-