

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 共享报告组
<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://console.aws.amazon.com/codesuite/codebuild](https://console.aws.amazon.com/codesuite/codebuild/home) /home 中打开 AWS CodeBuild 控制台。

1. 在导航窗格中，选择**报告组**。

1.  选择要共享的项目，然后选择**共享**。有关更多信息，请参阅《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 和 123456789012 所标识的 AWS 账户的根用户授予对带有 ARN `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 来识别共享报告组。

要标识和获取有关共享报告组及其报告的信息，请使用以下命令：
+  要查看与 ARNs 您共享的报告组，请运行`[list-shared-report-groups](https://docs.aws.amazon.com/cli/latest/reference/codebuild/list-shared-report-groups.html)`：

  ```
  aws codebuild list-shared-report-groups
  ```
+  要查看报告 ARNs 组中的报告，请`[list-reports-for-report-group](https://docs.aws.amazon.com/cli/latest/reference/codebuild/list-reports-for-report-group.html)`使用报告组 ARN 运行：

  ```
  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>

报告组使用者可以查看报告组、报告以及报告的测试用例结果。使用者无法编辑报告组或其报告，也无法使用报告组创建报告。