

Amazon CodeCatalyst 不再向新客戶開放。現有客戶可以繼續正常使用該服務。如需詳細資訊，請參閱[如何從 CodeCatalyst 遷移](migration.md)。

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

# 成品範例
<a name="workflows-working-artifacts-ex"></a>

下列範例示範如何在 Amazon CodeCatalyst 工作流程定義檔案中輸出、輸入和參考成品。

**Topics**
+ [範例：輸出成品](#workflows-working-artifacts-ex-basic)
+ [範例：輸入另一個動作產生的成品](#workflows-working-artifacts-ex-ref)
+ [範例：參考多個成品中的檔案](#workflows-working-artifacts-ex-ref-file)
+ [範例：參考單一成品中的檔案](#workflows-working-artifacts-ex-ref-file-one)
+ [範例：當 WorkflowSource 存在時，參考成品中的檔案](#workflows-working-artifacts-ex-ref-file-wf-source)
+ [範例：存在動作群組時參考成品中的檔案](#workflows-working-artifacts-ex-groups)

## 範例：輸出成品
<a name="workflows-working-artifacts-ex-basic"></a>

下列範例示範如何輸出包含兩個 .jar 檔案的成品。

```
Actions:
  Build:
    Identifier: aws/build@v1
    Outputs:
      Artifacts:
        - Name: ARTIFACT1
          Files:
            - build-output/file1.jar
            - build-output/file2.jar
```

## 範例：輸入另一個動作產生的成品
<a name="workflows-working-artifacts-ex-ref"></a>

下列範例示範如何輸出 `ARTIFACT4`中稱為 的成品`BuildActionA`，並將其輸入 `BuildActionB`。

```
Actions:
  BuildActionA:
    Identifier: aws/build@v1  
    Outputs:
      Artifacts:
        - Name: ARTIFACT4
          Files:
            - build-output/file1.jar
            - build-output/file2.jar
  BuildActionB:
    Identifier: aws/build@v1  
    Inputs:
      Artifacts:
        - ARTIFACT4
    Configuration:
```

## 範例：參考多個成品中的檔案
<a name="workflows-working-artifacts-ex-ref-file"></a>

下列範例示範如何在 `ART6`中輸出兩個名為 `ART5`和 的成品`BuildActionC`，然後在 `file5.txt`（在 下`ART5`) 中參考兩個名為 `file6.txt`（在成品 中） 和 `BuildActionD`（在成品 中`ART6`) 的檔案`Steps`。

**注意**  
如需參考檔案的詳細資訊，請參閱 [參考成品中的檔案](workflows-working-artifacts-refer-files.md)。

**注意**  
雖然範例顯示正在使用的`$CATALYST_SOURCE_DIR_ART5`字首，但您可以省略它。這是因為 `ART5`是*主要輸入*。若要進一步了解主要輸入，請參閱 [參考成品中的檔案](workflows-working-artifacts-refer-files.md)。

```
Actions:
  BuildActionC:
    Identifier: aws/build@v1  
    Outputs:
      Artifacts:
        - Name: ART5
          Files:
            - build-output/file5.txt
        - Name: ART6
          Files:
            - build-output/file6.txt
  BuildActionD:
    Identifier: aws/build@v1  
    Inputs:
      Artifacts:
        - ART5
        - ART6
    Configuration:
      Steps:
        - run: cd $CATALYST_SOURCE_DIR_ART5/build-output && cat file5.txt
        - run: cd $CATALYST_SOURCE_DIR_ART6/build-output && cat file6.txt
```

## 範例：參考單一成品中的檔案
<a name="workflows-working-artifacts-ex-ref-file-one"></a>

下列範例示範如何在 `ART7`中輸出名為 的一個成品`BuildActionE`，然後在 `file7.txt`（在成品 `ART7`下） 中參考 `BuildActionF`（在成品 )`Steps`。

請注意，參考不需要`build-output`目錄前面的`$CATALYST_SOURCE_DIR_`*成品名稱*字首，就像在 中一樣[範例：參考多個成品中的檔案](#workflows-working-artifacts-ex-ref-file)。這是因為 下只有一個指定項目`Inputs`。

**注意**  
如需參考檔案的詳細資訊，請參閱 [參考成品中的檔案](workflows-working-artifacts-refer-files.md)。

```
Actions:
  BuildActionE:
    Identifier: aws/build@v1  
    Outputs:
      Artifacts:
        - Name: ART7
          Files:
            - build-output/file7.txt
  BuildActionF:
    Identifier: aws/build@v1  
    Inputs:
      Artifacts:
        - ART7
    Configuration:
      Steps:
        - run: cd build-output && cat file7.txt
```

## 範例：當 WorkflowSource 存在時，參考成品中的檔案
<a name="workflows-working-artifacts-ex-ref-file-wf-source"></a>

下列範例示範如何在 `ART8`中輸出名為 的一個成品`BuildActionG`，然後在 `file8.txt`（在成品 `ART8`下） 中參考 `BuildActionH`（在成品 )`Steps`。

請注意，參考需要`$CATALYST_SOURCE_DIR_`*成品名稱*字首的方式，如同在 中一樣[範例：參考多個成品中的檔案](#workflows-working-artifacts-ex-ref-file)。這是因為在 `Inputs`（來源和成品） 下指定了多個項目，因此您需要 字首來指出在何處尋找檔案。

**注意**  
如需參考檔案的詳細資訊，請參閱 [參考成品中的檔案](workflows-working-artifacts-refer-files.md)。

```
Actions:
  BuildActionG:
    Identifier: aws/build@v1  
    Outputs:
      Artifacts:
        - Name: ART8
          Files:
            - build-output/file8.txt
  BuildActionH:
    Identifier: aws/build@v1  
    Inputs:
      Sources:
        - WorkflowSource
      Artifacts:
        - ART8
    Configuration:
      Steps:
        - run: cd $CATALYST_SOURCE_DIR_ART8/build-output && cat file8.txt
```

## 範例：存在動作群組時參考成品中的檔案
<a name="workflows-working-artifacts-ex-groups"></a>

下列範例示範如何輸出名為 `ActionGroup1`、 `ART9`的成品`ActionI`，然後在 中參考 `file9.txt`（成品 `ART9`)`ActionJ`。

如需參考檔案的詳細資訊，請參閱 [參考成品中的檔案](workflows-working-artifacts-refer-files.md)。

```
Actions:
  ActionGroup1:
    Actions:
      ActionI:
        Identifier: aws/build@v1
        Outputs:
          Artifacts:
            - Name: ART9
              Files:
                - build-output/file9.yml
      ActionJ:
        Identifier: aws/cfn-deploy@v1 
        Inputs:
          Sources:
            - WorkflowSource
          Artifacts:
            - ART9
        Configuration:
          template: /artifacts/ActionGroup1@ActionJ/ART9/build-output/file9.yml
```