

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

# 哪种类型的管道适合我？
<a name="pipeline-types-planning"></a>

管道类型由每个管道版本支持的一组特点与特征决定。

下面是每种管道类型的使用案例和特征摘要。


****  

|  | V1 类型 | V2 类型 | 特性 |  |  | 
| --- | --- | --- | --- | --- | --- | 
| 使用案例 |  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/codepipeline/latest/userguide/pipeline-types-planning.html)  |  [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/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) | 不支持 | 支持 | 
| [Commands 操作](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. 打开终端窗口。运行以下命令创建一个名为 **PipelineCostAnalyzer.py** 的新 python 脚本。

   ```
   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/)。