

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

# 共用報告群組
<a name="report-groups-sharing"></a>

報告群組共用可讓多個 AWS 帳戶或使用者檢視報告群組、其未過期的報告，以及其報告的測試結果。在此模型中，擁有報告群組的帳戶 (擁有者) 會與其他帳戶 (消費者) 共用報告群組。消費者無法編輯報告群組。報告會在建立後 30 天過期。

**Topics**
+ [共用報告群組](#report-groups-sharing-share)
+ [相關服務](#report-groups-sharing-related)
+ [存取與您共用的報告群組](report-groups-sharing-access-prereqs.md)
+ [取消共用共用報告群組](report-groups-sharing-unshare.md)
+ [識別共用報告群組](report-groups-sharing-identify.md)
+ [共用報告群組的許可](report-groups-sharing-perms.md)

## 共用報告群組
<a name="report-groups-sharing-share"></a>

 當您共用報告群組時，就會授予消費者報告群組及其報告的唯讀存取權。取用者可以使用 AWS CLI 來檢視報告群組、其報告，以及每個報告的測試案例結果。消費者無法：
+  在 CodeBuild 主控台中檢視共用報告群組或其報告。
+  編輯共用報告群組。
+  使用專案中共用報告群組的 ARN 來執行報告。指定共用報告群組的專案建置會失敗。

您可以使用 CodeBuild 主控台將報告群組新增至現有的資源共享。如果您想要將報告群組新增至新的資源共用，需先在 [AWS RAM 主控台](https://console.aws.amazon.com/ram)中建立它。

若要與組織單位或整個組織共用報告群組，必須啟用透過 AWS Organizations來共用的功能。如需詳細資訊，請參閱《*AWS RAM 使用者指南*》中的[透過 AWS Organizations啟用共用](https://docs.aws.amazon.com/ram/latest/userguide/getting-started-sharing.html)。

您可以使用 CodeBuild AWS RAM 主控台、主控台或 AWS CLI 來共用您擁有的報告群組。

**先決條件**  
若要共用報告群組， AWS 您的帳戶必須擁有該群組。您無法將已共用給您的報告群組再共用出去。

**共用您擁有的報告群組 (CodeBuild 主控台）**

1. 在 https：//[https://console.aws.amazon.com/codesuite/codebuild/home](https://console.aws.amazon.com/codesuite/codebuild/home) 開啟 AWS CodeBuild 主控台。

1. 在導覽窗格中，選擇 **Report groups (報告群組)**。

1.  選擇您要共用的專案，然後選擇 **Share (共用)**。如需詳細資訊，請參閱*《AWS RAM 使用者指南》*中的[建立資源共用](https://docs.aws.amazon.com/ram/latest/userguide/getting-started-sharing.html#getting-started-sharing-create)。

**共用您擁有的報告群組AWS RAM （主控台）**  
請參閱 *AWS RAM 使用者指南*中的[建立資源共用](https://docs.aws.amazon.com/ram/latest/userguide/working-with-sharing.html#working-with-sharing-create)。

**共用您擁有的報告群組 (AWS RAM 命令）**  
使用 [create-resource-share](https://docs.aws.amazon.com/cli/latest/reference/ram/create-resource-share.html) 命令。

 **共用您擁有的報告群組 (CodeBuild 命令）** 

使用 [put-resource-policy](https://docs.aws.amazon.com/cli/latest/reference/codebuild/put-resource-policy.html) 命令：

1. 建立名為 `policy.json` 的檔案，並將以下命令複製到其中。

------
#### [ JSON ]

****  

   ```
   {
      "Version":"2012-10-17",		 	 	 
      "Statement":[{
        "Effect":"Allow",
        "Principal":{
          "AWS":"111122223333"
        },
        "Action":[
          "codebuild:BatchGetReportGroups",
          "codebuild:BatchGetReports",
          "codebuild:ListReportsForReportGroup",
          "codebuild:DescribeTestCases"],
        "Resource":"arn:aws:iam::*:role/Service*"
      }]
    }
   ```

------

1. 使用報告群組 ARN 和識別符更新 `policy.json`，以與之共用。下列範例使用 Alice 的 ARN 和 123456789012 所識別 AWS 帳戶的根使用者`arn:aws:codebuild:us-west-2:123456789012:report-group/my-report-group`，授予報告群組的唯讀存取權。

------
#### [ JSON ]

****  

   ```
   {
      "Version":"2012-10-17",		 	 	 
      "Statement":[{
        "Effect":"Allow",
        "Principal":{
          "AWS": [
             "arn:aws:iam::123456789012:user/Alice",
             "123456789012"
           ]
        },
        "Action":[
          "codebuild:BatchGetReportGroups",
          "codebuild:BatchGetReports",
          "codebuild:ListReportsForReportGroup",
          "codebuild:DescribeTestCases"],
        "Resource":"arn:aws:codebuild:us-west-2:123456789012:report-group/my-report-group"
      }]
    }
   ```

------

1. 執行下列命令。

   ```
   aws codebuild put-resource-policy --resource-arn report-group-arn --policy file://policy.json
   ```

## 相關服務
<a name="report-groups-sharing-related"></a>

報告群組共用與 AWS Resource Access Manager (AWS RAM) 整合，這項服務可讓您與任何 AWS 帳戶或透過 共用 AWS 資源 AWS Organizations。與 共用您擁有的資源 AWS RAM，方法是建立*資源共用*，指定要共用的資源和取用者。消費者可以是 中的個別 AWS 帳戶 AWS Organizations、組織單位或整個組織 AWS Organizations。

如需詳細資訊，請參閱*「[AWS RAM 使用者指南」](https://docs.aws.amazon.com/ram/latest/userguide/)*。

# 存取與您共用的報告群組
<a name="report-groups-sharing-access-prereqs"></a>

若要存取共用報告群組，消費者的 IAM 角色需要 `BatchGetReportGroups` 許可。您可以將下列政策連接至其 IAM 角色：

```
{
    "Effect": "Allow",
    "Resource": [
        "*"
    ],
    "Action": [
        "codebuild:BatchGetReportGroups"
    ]
}
```

 如需詳細資訊，請參閱[使用 的身分型政策 AWS CodeBuild](auth-and-access-control-iam-identity-based-access-control.md)。

# 取消共用共用報告群組
<a name="report-groups-sharing-unshare"></a>

唯有其擁有者才能存取已取消共享的報告群組，包括其報告及測試案例結果。如果您取消共用報告群組，您之前與其共用的任何 AWS 帳戶或使用者都無法存取報告群組、其報告或報告中測試案例的結果。

若要取消共享您擁有的已共用報告存取，您必須從資源共享中移除它。您可以使用 AWS RAM 主控台或 AWS CLI 來執行此操作。

**取消共用您擁有的共用報告群組AWS RAM （主控台）**  
請參閱《*AWS RAM 使用者指南*》中的[更新資源共享](https://docs.aws.amazon.com/ram/latest/userguide/working-with-sharing.html#working-with-sharing-update)。

**取消共用您擁有的共用報告群組 (AWS RAM 命令）**  
使用 [disassociate-resource-share](https://docs.aws.amazon.com/cli/latest/reference/ram/disassociate-resource-share.html) 命令。

 ** 取消共用您擁有的 CodeBuild 命令的報告群組）** 

執行 [delete-resource-policy](https://docs.aws.amazon.com/cli/latest/reference/codebuild/delete-resource-policy.html) 命令並指定您要取消共享之報告群組的 ARN：

```
aws codebuild delete-resource-policy --resource-arn report-group-arn
```

# 識別共用報告群組
<a name="report-groups-sharing-identify"></a>

擁有者和取用者可以使用 AWS CLI 來識別共用報告群組。

若要識別並取得共用報告群組及其報告的資訊，請使用下列命令：
+  若要查看與您共用的報告群組 ARN，請執行 `[list-shared-report-groups](https://docs.aws.amazon.com/cli/latest/reference/codebuild/list-shared-report-groups.html)`：

  ```
  aws codebuild list-shared-report-groups
  ```
+  若要查看在報告存取中的報告 ARN，請使用報告群組 ARN 執行 `[list-reports-for-report-group](https://docs.aws.amazon.com/cli/latest/reference/codebuild/list-reports-for-report-group.html)`：

  ```
  aws codebuild list-reports-for-report-group --report-group-arn report-group-arn
  ```
+  若要查看報告中測試案例的相關資訊，請使用報告 ARN 執行 `[describe-test-cases](https://docs.aws.amazon.com/cli/latest/reference/codebuild/describe-test-cases.html)`：

  ```
  aws codebuild describe-test-cases --report-arn report-arn
  ```

   輸出看起來如下：

  ```
  {
      "testCases": [
          {
              "status": "FAILED",
              "name": "Test case 1",
              "expired": 1575916770.0,
              "reportArn": "report-arn",
              "prefix": "Cucumber tests for agent",
              "message": "A test message",
              "durationInNanoSeconds": 1540540,
              "testRawDataPath": "path-to-output-report-files"
          },
          {
              "status": "SUCCEEDED",
              "name": "Test case 2",
              "expired": 1575916770.0,
              "reportArn": "report-arn",
              "prefix": "Cucumber tests for agent",
              "message": "A test message",
              "durationInNanoSeconds": 1540540,
              "testRawDataPath": "path-to-output-report-files"
          }
      ]
  }
  ```

# 共用報告群組的許可
<a name="report-groups-sharing-perms"></a>

## 擁有者的許可
<a name="report-groups-perms-owner"></a>

報告群組的擁有者可以編輯報告群組，並在專案中指定該報告群組，以執行報告。

## 消費者的許可
<a name="report-groups-perms-consumer"></a>

報告群組消費者可以檢視報告群組、其報告，以及其報告的測試案例結果。消費者無法編輯報告群組或其報告，也無法用它來建立報告。