跳到正文
DEV Community· Himanshu Kumar·· 4 天前AI 評分35

GitLab CI 中,工作重試不應隱藏下一個工作

A job retry should not hide the next job in GitLab CI

AI 導讀

GitLab CLI 的 `glab ci view` 有一項修正提案,避免工作重試令其後的下游觸發工作從顯示結果中消失。新方法保留工作首次出現的位置,並以最後一次嘗試更新該項;回歸測試確認第二次嘗試和下游觸發工作均按順序顯示。修正及測試見 GitLab CLI 合併請求 !4483,相關檢查使用 `go test ./internal/commands/ci/view`。

正文

Himanshu Kumar

A retry changes which attempt you want to see. It should never make an unrelated job disappear from the display. That distinction is behind a small fix proposed for GitLab CLI’s glab ci view.

The three-entry test

The view collects pipeline jobs and then appends downstream pipeline triggers. Consider the smallest input that exposes the problem:

test / unit       attempt 1
test / unit       attempt 2
deploy / trigger downstream pipeline

The old display helper treated the first repeated job as the start of a suffix containing only retries. It found attempt 2 for unit, but stopped allocating display slots at the repeat. The distinct downstream trigger after it therefore vanished from the CLI view. This was a display bug. The trigger itself was still part of the pipeline.

Keep the slot, update the attempt

The proposed helper walks the entire input once. A map records the output index for each (stage, name) pair. On the first occurrence it appends the job. On a repeat it replaces the entry at that index. Each job keeps the position where it first appeared, while the last attempt supplied for that job is the one shown. The downstream trigger still gets its own slot.

Using a pair as the key also keeps ("ab", "c") distinct from ("a", "bc"). Both would turn into abc if you simply concatenated the strings.

Test what must survive

The regression test passes in both attempts followed by the trigger, then asserts that the output contains the second attempt and the trigger, in that order. A test that checks only which retry wins would miss the disappearing row. The same test shape is useful for event feeds and task lists whenever a later event updates an item that already has a position.

The patch and test are in GitLab CLI merge request !4483. The focused package check was go test ./internal/commands/ci/view.

AI disclosure: This article was drafted with AI assistance and checked against the public patch and its test results.

來源:DEV Community · dev.to