使用 的 CodeConnections 範例 AWS CLI - AWS Command Line Interface

本文件 AWS CLI 僅適用於 第 1 版。如需 第 2 版的相關文件 AWS CLI,請參閱 第 2 版使用者指南

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 的 CodeConnections 範例 AWS CLI

下列程式碼範例示範如何使用 AWS Command Line Interface 搭配 CodeConnections 來執行動作和實作常見案例。

Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數,但您可以在其相關情境中查看內容中的動作。

每個範例都包含完整原始程式碼的連結,您可以在其中找到如何在內容中設定和執行程式碼的指示。

主題

動作

下列程式碼範例示範如何使用 create-connection

AWS CLI

建立連線

下列create-connection範例示範如何建立與第三方儲存庫的連線。此範例會建立第三方供應商為 Bitbucket 的連線。

根據預設,透過 CLI AWS 或 AWS CloudFormation 建立的連線處於待定狀態。使用 CLI 或 AWS CloudFormation 建立連線後,請使用 主控台編輯連線,使其狀態可用。

aws codestar-connections create-connection \ --provider-type Bitbucket \ --connection-name MyConnection

輸出:

{ "ConnectionArn": "arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f" }

如需詳細資訊,請參閱《 開發人員工具主控台使用者指南》中的建立連線

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 CreateConnection

下列程式碼範例示範如何使用 create-host

AWS CLI

建立主機

下列create-host範例示範如何建立主機,以代表安裝第三方供應商之基礎設施的端點。此範例會建立主機,其中第三方安裝的提供者是 GitHub Enterprise Server。

透過 CLI AWS 建立的主機預設為待定狀態。使用 CLI 建立主機之後,請使用 主控台或 CLI 來設定主機,使其狀態可用。

aws codestar-connections create-host \ --name MyHost \ --provider-type GitHubEnterpriseServer \ --provider-endpoint "https://my-instance.dev"

輸出:

{ "HostArn": "arn:aws:codestar-connections:us-east-1:123456789012:host/My-Host-28aef605" }

如需詳細資訊,請參閱《 開發人員工具主控台使用者指南》中的建立主機 (CLI)

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 CreateHost

下列程式碼範例示範如何使用 delete-connection

AWS CLI

刪除連線

下列delete-connection範例示範如何刪除連線。

aws codestar-connections delete-connection \ --connection-arn arn:aws:codestar-connections:us-west-2:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f

此命令不會產生輸出。

如需詳細資訊,請參閱《 開發人員工具主控台使用者指南》中的刪除連線 (CLI)

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DeleteConnection

下列程式碼範例示範如何使用 delete-host

AWS CLI

刪除主機

下列delete-host範例示範如何刪除主機。您必須先刪除與主機相關聯的所有連線,才能刪除該主機。

aws codestar-connections delete-host \ --host-arn "arn:aws:codestar-connections:us-east-1 :123456789012:host/My-Host-28aef605"

此命令不會產生輸出。

如需詳細資訊,請參閱《 開發人員工具主控台使用者指南》中的刪除主機 (CLI)

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DeleteHost

下列程式碼範例示範如何使用 get-connection

AWS CLI

取得連線的相關資訊

下列get-connection範例顯示連線的詳細資訊。

aws codestar-connections get-connection \ --connection-arn arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f

輸出:

{ "Connection": { "ConnectionName": "MyConnection", "ConnectionArn": "arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f", "ProviderType": "Bitbucket", "OwnerAccountId": "123456789012", "ConnectionStatus": "AVAILABLE" } }

如需詳細資訊,請參閱《 開發人員工具主控台使用者指南》中的檢視連線詳細資訊

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 GetConnection

下列程式碼範例示範如何使用 get-host

AWS CLI

取得主機的相關資訊

下列get-host範例顯示主機的詳細資訊:

aws codestar-connections get-host \ --host-arn arn:aws:codestar-connections:us-east-1:123456789012:host/MyHost-28aef605

輸出:

{ "Name": "MyHost", "Status": "AVAILABLE", "ProviderType": "GitHubEnterpriseServer", "ProviderEndpoint": "https://test-instance-1.dev/" }

如需詳細資訊,請參閱《 開發人員工具主控台使用者指南》中的檢視主機詳細資訊 (CLI)

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 GetHost

下列程式碼範例示範如何使用 list-connections

AWS CLI

列出連線

下列list-connections範例會擷取您帳戶中所有 Bitbucket 提供者類型的連線清單:

aws codestar-connections list-connections \ --provider-type Bitbucket \ --max-results 5 \ --next-token: next-token

輸出:

{ "Connections": [ { "ConnectionName": "my-connection", "ProviderType": "Bitbucket", "Status": "PENDING", "ARN": "arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f", "OwnerAccountId": "123456789012" }, { "ConnectionName": "my-other-connection", "ProviderType": "Bitbucket", "Status": "AVAILABLE", "ARN": "arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f", "OwnerAccountId": "123456789012" }, ], "NextToken": "next-token" }

如需詳細資訊,請參閱《 開發人員工具主控台使用者指南》中的列出連線 (CLI)

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 ListConnections

下列程式碼範例示範如何使用 list-hosts

AWS CLI

列出主機

下列list-hosts範例會擷取您帳戶中所有主機的清單。

aws codestar-connections list-hosts

輸出:

{ "Hosts": [ { "Name": "My-Host", "HostArn": "arn:aws:codestar-connections:us-east-1:123456789012:host/My-Host-28aef605", "ProviderType": "GitHubEnterpriseServer", "ProviderEndpoint": "https://my-instance.test.dev", "Status": "AVAILABLE" } ] }

如需詳細資訊,請參閱《 開發人員工具主控台使用者指南》中的列出主機 (CLI)

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 ListHosts

下列程式碼範例示範如何使用 list-tags-for-resource

AWS CLI

列出標籤

下列list-tags-for-resource範例會擷取連接至指定連線資源的所有標籤清單。

aws codestar-connections list-tags-for-resource \ --resource-arn arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f

輸出:

{ "Tags": [ { "Key": "Project", "Value": "ProjectA" }, { "Key": "ReadOnly", "Value": "true" } ] }

如需詳細資訊,請參閱《 開發人員工具主控台使用者指南》中的檢視連線資源的標籤

下列程式碼範例示範如何使用 tag-resource

AWS CLI

標記資源

下列tag-resource範例會將一組提供的標籤與連線建立關聯。使用此命令來新增或編輯標籤。

aws codestar-connections tag-resource \ --resource-arn arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f \ --tags Key=Project,Value=ProjectA Key=IscontainerBased,Value=true

此命令不會產生輸出。

如需詳細資訊,請參閱《 開發人員工具主控台使用者指南》中的將標籤新增至連線資源

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 TagResource

下列程式碼範例示範如何使用 untag-resource

AWS CLI

從連線資源移除 AWS 標籤

以下內容會從指定的資源untag-resource移除標籤。

aws codestar-connections untag-resource \ --resource-arn arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f \ --tag-keys Project ReadOnly

輸出:

{ "Tags": [] }

如需詳細資訊,請參閱《 開發人員工具主控台使用者指南》中的從連線資源移除標籤

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 UntagResource