

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

# 哪種管道適合我？
<a name="pipeline-types-planning"></a>

管道類型取決於每個管道版本支援的一組特性和功能。

以下是每種管道類型可用的使用案例和特性摘要。


****  

|  | V1 類型 | V2 類型 | 特性 |  |  | 
| --- | --- | --- | --- | --- | --- | 
| 使用案例 |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/codepipeline/latest/userguide/pipeline-types-planning.html)  |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/codepipeline/latest/userguide/pipeline-types-planning.html)  | 
| [動作層級變數](https://docs.aws.amazon.com/codepipeline/latest/userguide/reference-variables.html) | 支援 | 支援 | 
| [PARALLEL 執行模式](https://docs.aws.amazon.com/codepipeline/latest/userguide/welcome.html#concepts-how-it-works-executions-parallel) | 不支援 | 支援 | 
| [管道層級變數](https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials-pipeline-variables.html) | 不支援 | 支援 | 
| [QUEUED 執行模式](https://docs.aws.amazon.com/codepipeline/latest/userguide/welcome.html#concepts-how-it-works-executions-queued) | 不支援 | 支援 | 
| [管道階段的轉返](https://docs.aws.amazon.com/codepipeline/latest/userguide/stage-rollback.html) | 不支援 | 支援 | 
| [來源修訂覆寫](https://docs.aws.amazon.com/codepipeline/latest/userguide/pipelines-trigger-source-overrides.html) | 不支援 | 支援 | 
| [階段條件](https://docs.aws.amazon.com/codepipeline/latest/userguide/stage-conditions.html) | 不支援 | 支援 | 
| [觸發和篩選 Git 標籤、提取請求、分支或檔案路徑](https://docs.aws.amazon.com/codepipeline/latest/userguide/pipelines-filter.html) | 不支援 | 支援 | 
| [命令動作](https://docs.aws.amazon.com/codepipeline/latest/userguide/action-reference-Commands.html) | 不支援 | 支援 | 
| [ 使用略過結果建立項目條件](https://docs.aws.amazon.com/codepipeline/latest/userguide/stage-conditions.html#stage-conditions-entry-skip) | 不支援 | 支援 | 
| [設定自動重試失敗的階段](https://docs.aws.amazon.com/codepipeline/latest/userguide/stage-retry.html#stage-retry-auto) | 不支援 | 支援 | 

如需 CodePipeline 定價的資訊，請參閱 [定價](https://aws.amazon.com/codepipeline/pricing/)。

您可以建立並執行 Python 指令碼，以協助您分析將 V1 類型管道移至 V2 類型管道的潛在成本。

**注意**  
以下範例指令碼僅用於示範和評估目的。它不是引號工具，不保證實際使用 V2 類型管道的成本，也不包含任何可能適用的稅金。如需 CodePipeline 定價的資訊，請參閱 [定價](https://aws.amazon.com/codepipeline/pricing/)。

**建立和執行指令碼，以協助您評估將 V1 類型管道移至 V2 類型管道的成本**

1. 下載並安裝 python。

1. 開啟終端機視窗。執行下列命令來建立新的 python 指令碼，名為 **PipelineCostAnalyzer.py**。

   ```
   vi PipelineCostAnalyzer.py
   ```

1. 將下列程式碼複製並貼到 **PipelineCostAnalyzer.py** 指令碼。

   ```
   import boto3
   import sys
   import math
   from datetime import datetime, timedelta, timezone
   
   if len(sys.argv) < 3:
       raise Exception("Please provide region name and pipeline name as arguments. Example usage: python PipelineCostAnalyzer.py us-east-1 MyPipeline")
   session = boto3.Session(profile_name='default', region_name=sys.argv[1])
   pipeline = sys.argv[2]
   codepipeline = session.client('codepipeline')
   
   def analyze_cost_in_v2(pipeline_name):
       if codepipeline.get_pipeline(name=pipeline)['pipeline']['pipelineType'] == 'V2':
           raise Exception("Provided pipeline is already of type V2.")
       total_action_executions = 0
       total_blling_action_executions = 0
       total_action_execution_minutes = 0
       cost = 0.0
       hasNextToken = True
       nextToken = ""
   
       while hasNextToken:
           if nextToken=="":
               response = codepipeline.list_action_executions(pipelineName=pipeline_name)
           else:
               response = codepipeline.list_action_executions(pipelineName=pipeline_name, nextToken=nextToken)
           if 'nextToken' in response:
               nextToken = response['nextToken']
           else:
               hasNextToken= False
           for action_execution in response['actionExecutionDetails']:
               start_time = action_execution['startTime']
               end_time = action_execution['lastUpdateTime']
               if (start_time < (datetime.now(timezone.utc) - timedelta(days=30))):
                   hasNextToken= False
                   continue
               total_action_executions += 1
               if (action_execution['status'] in ['Succeeded', 'Failed', 'Stopped']):
                   action_owner = action_execution['input']['actionTypeId']['owner']
                   action_category = action_execution['input']['actionTypeId']['category']
                   if (action_owner == 'Custom' or (action_owner == 'AWS' and action_category == 'Approval')):
                       continue
                   
                   total_blling_action_executions += 1
                   action_execution_minutes = (end_time - start_time).total_seconds()/60
                   action_execution_cost = math.ceil(action_execution_minutes) * 0.002
                   total_action_execution_minutes += action_execution_minutes
                   cost = round(cost + action_execution_cost, 2)
   
       print ("{:<40}".format('Activity in last 30 days:'))
       print ("| {:<40} | {:<10}".format('___________________________________', '__________________'))
       print ("| {:<40} | {:<10}".format('Total action executions:', total_action_executions))
       print ("| {:<40} | {:<10}".format('Total billing action executions:', total_blling_action_executions))
       print ("| {:<40} | {:<10}".format('Total billing action execution minutes:', round(total_action_execution_minutes, 2)))
       print ("| {:<40} | {:<10}".format('Cost of moving to V2 in $:', cost - 1))
   
   analyze_cost_in_v2(pipeline)
   ```

1. 從終端機或命令提示字元中，將目錄變更為您建立分析器指令碼的位置。

   從該目錄中，執行下列命令，其中 *region* 是您建立要分析之 V1 管道 AWS 區域 的 。您也可以選擇性地評估特定管道，方法是提供其名稱：

   ```
   python3 PipelineCostAnalyzer.py region --pipelineName
   ```

   例如，執行下列命令來執行名為 **PipelineCostAnalyzer.py** 的 python 指令碼。在此範例中，區域為 `us-west-2`。

   ```
   python3 PipelineCostAnalyzer.py us-west-2
   ```
**注意**  
除非您指定特定的管道名稱，否則此指令碼將分析指定 AWS 區域 中的所有 V1 管道。

1. 在下列來自指令碼的範例輸出中，我們可以看到動作執行的清單、有資格計費的動作執行的清單、這些動作執行的總執行時間，以及在 V2 管道中執行這些動作的預估成本。

   ```
   Activity in last 30 days: 
    | ___________________________________      | __________________
    | Total action executions:                 | 9         
    | Total billing action executions:         | 9         
    | Total billing action execution minutes:  | 5.59      
    | Cost of moving to V2 in $:               | -0.76
   ```

   在此範例中，最後一列中的負值代表移動至 V2 類型管道可能儲存的預估數量。
**注意**  
顯示成本和其他資訊的指令碼輸出和相關範例僅為預估值。它們僅用於示範和評估目的，不保證任何實際的節省。如需 CodePipeline 定價的資訊，請參閱 [定價](https://aws.amazon.com/codepipeline/pricing/)。