Use ListProjects
with an AWS SDK or CLI
The following code examples show how to use ListProjects
.
- 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 projects. /*! \param sortType: 'SortOrderType' type. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::CodeBuild::listProjects(Aws::CodeBuild::Model::SortOrderType sortType, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::CodeBuild::CodeBuildClient codeBuildClient(clientConfiguration); Aws::CodeBuild::Model::ListProjectsRequest listProjectsRequest; listProjectsRequest.SetSortOrder(sortType); Aws::String nextToken; // Next token for pagination. Aws::Vector<Aws::String> allProjects; do { if (!nextToken.empty()) { listProjectsRequest.SetNextToken(nextToken); } Aws::CodeBuild::Model::ListProjectsOutcome outcome = codeBuildClient.ListProjects( listProjectsRequest); if (outcome.IsSuccess()) { const Aws::Vector<Aws::String> &projects = outcome.GetResult().GetProjects(); allProjects.insert(allProjects.end(), projects.begin(), projects.end()); nextToken = outcome.GetResult().GetNextToken(); } else { std::cerr << "Error listing projects" << outcome.GetError().GetMessage() << std::endl; } } while (!nextToken.empty()); std::cout << allProjects.size() << " project(s) found." << std::endl; for (auto project: allProjects) { std::cout << project << std::endl; } return true; }
-
For API details, see ListProjects in AWS SDK for C++ API Reference.
-
- CLI
-
- AWS CLI
-
To get a list of AWS CodeBuild build project names.
The following
list-projects
example gets a list of CodeBuild build projects sorted by name in ascending order.aws codebuild list-projects --sort-by
NAME
--sort-orderASCENDING
The output includes a
nextToken
value which indicates that there is more output available.{ "nextToken": "Ci33ACF6...The full token has been omitted for brevity...U+AkMx8=", "projects": [ "codebuild-demo-project", "codebuild-demo-project2", ... The full list of build project names has been omitted for brevity ... "codebuild-demo-project99" ] }
Run this command again and provide the
nextToken
value from 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-projects --sort-by
NAME
--sort-orderASCENDING
--next-tokenCi33ACF6...The
full
token
has
been
omitted
for
brevity...U+AkMx8=
{
"projects":[
"codebuild-demo-project100", "codebuild-demo-project101",...
The
full
list
of
build
project
names
has
been
omitted
for
brevity
...
"codebuild-demo-project122"
]
}
For more information, see View a List of Build Project Names (AWS CLI) in the AWS CodeBuild User Guide.
-
For API details, see ListProjects
in AWS CLI Command Reference.
-
For a complete list of AWS SDK developer guides and code examples, see Using this service with an AWS SDK. This topic also includes information about getting started and details about previous SDK versions.