Jfrog Pipelines嵌入流水线父步骤因子步骤跳过失败的解决咨询
Jfrog Pipelines子步骤跳过时让父步骤显示成功的方法
默认情况下,用TriggerPipeline触发的子流水线步骤被跳过(无其他失败情况)时,父步骤会被标记为失败。要解决这个问题,可以从子步骤状态主动控制和父步骤结果覆盖两个层面处理:
方法一:子流水线内手动管控跳过状态
如果子步骤是因特定条件需要跳过,不要依赖系统默认的跳过标记,而是手动将其设置为成功状态。比如在子步骤的执行阶段判断跳过条件,满足时直接标记步骤成功:
修改后的完整流水线示例:
pipelines: - name: top_pipeline steps: - name: scan_controller type: TriggerPipeline configuration: pipelineName: scanner_pipeline stepName: scan_it integrations: - name: myPlatformToken environmentVariables: scan_target: default: "hello-world" allowCustom: true values: - "vault" - "redis" - "postgresql" - "hello-world" execution: onStart: - set_trigger_payload pipelineVariables "scan_target=${scan_target}" - set_trigger_payload stepVariables "notify=email" "uploadReport=true" onComplete: # 检测子流水线状态,若为跳过则强制设置父步骤为成功 - if [ "$nested_run_status" == "Skipped" ]; then set_step_status succeeded; fi - echo "最终状态为 $nested_run_status" - name: scanner_pipeline steps: - name: scan_it type: Bash execution: onExecute: # 模拟跳过条件:当目标为hello-world时跳过扫描 if [ "${scan_target}" == "hello-world" ]; then echo "扫描目标为hello-world,跳过扫描流程" set_step_status succeeded exit 0 fi echo "待扫描镜像为 $scan_target." echo "由父步骤触发:$parent_step_url"
方法二:父步骤根据子流水线状态强制覆盖结果
如果子流水线确实会产生Skipped状态,可在父步骤的onComplete阶段,通过内置变量$nested_run_status判断子流水线状态,手动将父步骤标记为成功。这是修正父步骤失败状态的核心操作。
关键代码片段:
- if [ "$nested_run_status" == "Skipped" ]; then set_step_status succeeded; fi
注意事项
$nested_run_status是Jfrog Pipelines的内置变量,返回值包括Succeeded、Failed、Skipped等子流水线的最终状态;- 若需适配更复杂的状态逻辑,可扩展判断语句,比如同时将
Skipped和Succeeded都设为父步骤成功。
内容的提问来源于stack exchange,提问作者Nitin Dagdi
相关产品推荐
相关产品推荐

