本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
搭ListProjects
配 AWS SDK或使用 CLI
下列程式碼範例會示範如何使用ListProjects
。
- C++
-
- SDK對於 C ++
-
注意
還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 //! 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; }
-
如需詳API細資訊,請參閱AWS SDK for C++ API參考ListProjects中的。
-
- CLI
-
- AWS CLI
-
獲取 AWS CodeBuild 構建項目名稱的列表。
下列
list-projects
範例會取得依名稱遞增順序排序的 CodeBuild 建置專案清單。aws codebuild list-projects --sort-by
NAME
--sort-orderASCENDING
輸出包括一個
nextToken
值,表示有更多可用的輸出。{ "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" ] }
再次執行此命令,並提供上一個回應中的
nextToken
值作為參數,以取得輸出的下一部分。重複此步驟,直到您沒有收到回應中的nextToken
值為止。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"
]
}
如需詳細資訊,請參閱AWS CodeBuild 使用指南中的檢視組建專案名稱清單 (AWS CLI)。
-
如需詳API細資訊,請參閱AWS CLI 指令參考ListProjects
中的。
-
如需 AWS SDK開發人員指南和程式碼範例的完整清單,請參閱將此服務與 搭配使用 AWS SDK。本主題也包含有關入門的資訊以及舊SDK版的詳細資訊。
ListBuilds
StartBuild