AWS CLI 实战:使用 `aws codepipeline list-pipeline-executions` 查看 CodePipeline 流水线执行历史

AWS CLI 实战:使用 `aws codepipeline list-pipeline-executions` 查看 CodePipeline 流水线执行历史 AWS CLI 实战使用aws codepipeline list-pipeline-executions查看 CodePipeline 流水线执行历史【免费下载链接】aws-cliUniversal Command Line Interface for Amazon Web Services项目地址: https://gitcode.com/GitHub_Trending/aw/aws-cli导读本文以 AWS CLI 官方示例文档 list-pipeline-executions.rst 为核心讲解如何通过aws codepipeline list-pipeline-executions命令查看指定流水线Pipeline的执行历史。你将掌握该命令的完整用法、核心参数pipelineName、maxResults、filter、nextToken、返回结果中每个字段执行 ID、状态、时间戳等的语义以及结合当前仓库中的服务模型定义service-2.json与分页配置paginators-1.json进行源码级验证帮助你快速定位 CI/CD 流水线的运行状况与故障排查。命令概览查看流水线执行历史在 AWS CodePipeline 中每次流水线运行都会产生一条**流水线执行Pipeline Execution**记录。list-pipeline-executions命令用于获取某条流水线最近若干次执行的摘要信息是日常巡检、审计与故障定位最常用的命令之一。仓库中该命令的官方示例原文如下list-pipeline-executions.rstaws codepipeline list-pipeline-executions \ --pipeline-name MyPipeline执行后返回该流水线的执行历史摘要输出格式如下{ pipelineExecutionSummaries: [ { lastUpdateTime: 1496380678.648, pipelineExecutionId: 7cf7f7cb-3137-539g-j458-d7eu3EXAMPLE, startTime: 1496380258.243, status: Succeeded }, { lastUpdateTime: 1496591045.634, pipelineExecutionId: 3137f7cb-8d494hj4-039j-d84l-d7eu3EXAMPLE, startTime: 1496590401.222, status: Succeeded }, { lastUpdateTime: 1496946071.6456, pipelineExecutionId: 4992f7jf-7cf7-913k-k334-d7eu3EXAMPLE, startTime: 1496945471.5645, status: Succeeded } ] }从输出可以看到每次执行摘要至少包含以下三个核心字段字段含义pipelineExecutionId流水线执行的唯一 ID格式为 UUID详见下文执行 ID 的格式约束status执行状态示例中为Succeeded成功startTime执行开始时间Unix 时间戳秒lastUpdateTime执行状态最后一次变更的时间Unix 时间戳秒请求参数详解根据仓库中的服务模型 service-2.jsonListPipelineExecutionsInput形状定义约第 3233 行起该命令支持以下参数--pipeline-name必填要查询执行历史的流水线名称。约束长度 1100 个字符仅允许[A-Za-z0-9.\-_]等字符对应PipelineName形状定义见 service-2.json若指定的流水线不存在服务端将返回PipelineNotFoundExceptionThe pipeline was specified in an invalid format or cannot be found.。--max-results单次调用最多返回的执行摘要条数。默认值为100流水线历史记录仅保留最近 12 个月按执行开始时间计算若结果超过单次上限可通过返回的nextToken发起下一次调用获取剩余结果。--filter按条件过滤执行历史目前仅支持一个子参数succeededInStage仅返回在当前流水线版本中指定阶段Stage执行成功的流水线执行记录注意使用某阶段成功过滤器时服务端只返回2024 年 2 月 1 日之后的当前流水线版本中的全部执行记录见 service-2.json 中操作文档的 note 说明。--next-token上一轮list-pipeline-executions调用返回的分页令牌用于获取后续批次的结果。返回字段深度解析返回体ListPipelineExecutionsOutput包含两个成员service-2.jsonpipelineExecutionSummaries本次返回的执行摘要列表nextToken若还有更多结果返回该令牌用于下一页查询否则不返回。每个摘要对象PipelineExecutionSummary定义见 service-2.json除示例中的四个字段外还可能包含以下可选字段字段类型/取值含义statusSummarystring流水线执行的状态摘要文本sourceRevisions列表触发本次执行的上游源工件修订Source Revision列表trigger对象触发本次执行的交互或事件含triggerType与triggerDetail例如 webhook ARN、start-pipeline-execution调用的用户 ARN 等stopTrigger对象导致本次执行被停止的交互信息executionModeQUEUED/SUPERSEDED/PARALLEL流水线处理多次执行的模式默认SUPERSEDED新执行取代等待中的旧执行executionTypeSTANDARD/ROLLBACK执行类型ROLLBACK表示回滚型执行rollbackMetadata对象回滚目标执行 ID 等回滚元数据status字段的七种取值根据PipelineExecutionStatus枚举定义service-2.json状态完整取值如下Cancelled执行被取消InProgress执行正在进行中Stopped执行已被手动停止Stopping执行收到停止请求正在完成或放弃进行中的动作取决于停止模式Succeeded执行成功完成示例中的状态Superseded执行在等待下一阶段时被更新的执行取代并继续推进流水线Failed执行未成功完成。执行 ID 的格式约束pipelineExecutionId遵循PipelineExecutionId形状的 UUID 格式约束service-2.json[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}即8-4-4-4-12的小写十六进制分段形式。示例中的 ID 带EXAMPLE后缀是文档中常见的脱敏写法。时间戳说明startTime与lastUpdateTime均为 Unix 时间戳浮点数单位为秒如1496380258.243。在 AWS CLI 中可直接配合--output json解析或用date等工具换算为可读时间date -d 1496380258.243使用--max-results与--next-token分页遍历当执行历史较多时单次调用只返回部分结果。仓库的分页配置paginators-1.json明确声明了该操作的分页规则ListPipelineExecutions: { input_token: nextToken, limit_key: maxResults, output_token: nextToken, result_key: pipelineExecutionSummaries }这意味着入参令牌为nextToken限制条数参数为maxResults出参令牌同样为nextToken结果列表的键为pipelineExecutionSummaries。因此 AWS CLI 可以直接通过--max-items参数享受内置分页能力例如每页最多返回 2 条aws codepipeline list-pipeline-executions \ --pipeline-name MyPipeline \ --max-items 2如需手动分页可先取返回体中的nextToken再作为下一次调用的--next-token传入直至不再返回nextTokenaws codepipeline list-pipeline-executions \ --pipeline-name MyPipeline \ --next-token 上轮返回的nextToken结合过滤与输出定制进行实战排查只查看执行 ID 与状态利用--query精简输出便于脚本消费aws codepipeline list-pipeline-executions \ --pipeline-name MyPipeline \ --query pipelineExecutionSummaries[].[pipelineExecutionId, status, startTime] \ --output table按某阶段成功过滤若只想关注在指定阶段如Deploy执行成功的记录aws codepipeline list-pipeline-executions \ --pipeline-name MyPipeline \ --filter {succeededInStage: Deploy}注意该过滤结果只覆盖 2024 年 2 月 1 日之后、当前流水线版本中的执行记录。结合--query快速定位失败执行aws codepipeline list-pipeline-executions \ --pipeline-name MyPipeline \ --query pipelineExecutionSummaries[?statusFailed] \ --output json与其他 CodePipeline 命令的配合使用查询到pipelineExecutionId后可用 get-pipeline-state 查看流水线各阶段与动作的最新状态需要查看某次执行中每个动作Action的执行细节时可使用 list-action-executions手动触发一次新执行使用 start-pipeline-execution手动停止执行使用 stop-pipeline-execution失败后重试某阶段使用 retry-stage-execution。常见错误与处理根据 service-2.json 中该操作的错误定义调用时可能遇到ValidationException参数校验失败例如--pipeline-name超过 100 字符或包含非法字符PipelineNotFoundException指定的流水线不存在或格式非法InvalidNextTokenException--next-token无效或已过期请重新从头开始分页。小结aws codepipeline list-pipeline-executions是查看 AWS CodePipeline 执行历史的入口命令。本文结合仓库中的官方示例 list-pipeline-executions.rst 与服务模型 service-2.json、分页配置 paginators-1.json完整覆盖了命令用法、参数语义、返回字段、分页遍历、状态枚举与异常处理。日常运维中将该命令与--query、--filter及配套命令组合使用即可高效完成流水线健康巡检与故障定位。【免费下载链接】aws-cliUniversal Command Line Interface for Amazon Web Services项目地址: https://gitcode.com/GitHub_Trending/aw/aws-cli创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考