BlueGit

timfa bluegit

CI: Obsolete-weergave voor jobs gestopt door een nieuwere pipeline, juiste annuleerreden, duidelijke timeoutregel

- jobs.failure_reason: canceled_by_newer_pipeline / canceled_by_user / job_execution_timeout / ...
- UI/API/webhook/bg: Obsolete met tooltip, cancel_reason, failure_reason, display_status; status blijft canceled
- runner schreef bij handmatig annuleren ten onrechte 'newer pipeline'; nu 'canceled by a user'
- timeout: 'Job timed out after X (limit: bron)' in ingebouwde en aparte runner
- migratie bestaande jobs, docs, tests

timfa Tim Falken · pushed by timfa

Authored 2026-10-25 · 3 weeks ago

Hash
9bb77ee74a9f3b620bd54bc00da9593a62760424
Parent
811ca877
Pipeline
Passed
22 files changed +440 −61
cmd/bluegit-runner/main.go +6 −1
@@ -443,8 +443,13 @@ func (c *client) runJob(parent context.Context, pl runner.RemotePayload) {
443 443 ctx, cancel := context.WithCancel(parent)
444 444 defer cancel()
445 445 runCtx := ctx
446 limitSource := runner.TimeoutFromServer
447 if pl.Job.Timeout > 0 {
448 limitSource = runner.TimeoutFromJob
449 }
446 450 if m := c.settings().JobTimeoutMin; m > 0 && (pl.Timeout <= 0 || int64(m*60) < pl.Timeout) {
447 451 pl.Timeout = int64(m * 60)
452 limitSource = runner.TimeoutFromRunner
448 453 }
449 454 if pl.Timeout > 0 {
450 455 var tc context.CancelFunc
@@ -557,7 +562,7 @@ func (c *client) runJob(parent context.Context, pl runner.RemotePayload) {
557 562 case wasCanceled:
558 563 status = "canceled"
559 564 case errors.Is(runCtx.Err(), context.DeadlineExceeded):
560 status, msg = "failed", "job_execution_timeout: "+err.Error()
565 status, msg = "failed", "job_execution_timeout: "+runner.TimedOutLine(time.Duration(pl.Timeout)*time.Second, limitSource)
561 566 default:
562 567 status, msg = "failed", err.Error()
563 568 }
@@ -443,8 +443,13 @@ func (c *client) runJob(parent context.Context, pl runner.RemotePayload) {
443 ctx, cancel := context.WithCancel(parent)
443 ctx, cancel := context.WithCancel(parent)
444 defer cancel()
444 defer cancel()
445 runCtx := ctx
445 runCtx := ctx
446 limitSource := runner.TimeoutFromServer
447 if pl.Job.Timeout > 0 {
448 limitSource = runner.TimeoutFromJob
449 }
446 if m := c.settings().JobTimeoutMin; m > 0 && (pl.Timeout <= 0 || int64(m*60) < pl.Timeout) {
450 if m := c.settings().JobTimeoutMin; m > 0 && (pl.Timeout <= 0 || int64(m*60) < pl.Timeout) {
447 pl.Timeout = int64(m * 60)
451 pl.Timeout = int64(m * 60)
452 limitSource = runner.TimeoutFromRunner
448 }
453 }
449 if pl.Timeout > 0 {
454 if pl.Timeout > 0 {
450 var tc context.CancelFunc
455 var tc context.CancelFunc
@@ -557,7 +562,7 @@ func (c *client) runJob(parent context.Context, pl runner.RemotePayload) {
557 case wasCanceled:
562 case wasCanceled:
558 status = "canceled"
563 status = "canceled"
559 case errors.Is(runCtx.Err(), context.DeadlineExceeded):
564 case errors.Is(runCtx.Err(), context.DeadlineExceeded):
560 status, msg = "failed", "job_execution_timeout: "+err.Error()
565 status, msg = "failed", "job_execution_timeout: "+runner.TimedOutLine(time.Duration(pl.Timeout)*time.Second, limitSource)
561 default:
566 default:
562 status, msg = "failed", err.Error()
567 status, msg = "failed", err.Error()
563 }
568 }
docs/CI.md +10 −1
@@ -52,7 +52,7 @@ jobs:
52 52 | `parallel:matrix` | Per lijstitem het cartesisch product, daarna aan elkaar. De job heet `naam: [waarde, waarde]`. De sleutels worden variabelen, in de volgorde uit het bestand. |
53 53 | `services` | Sidecar-containers op een eigen Docker-netwerk met de job. Een tekst, of `name`, `alias`, `command`, `entrypoint` en `variables`. Zonder alias is dat het imagenaam zonder registry en tag. |
54 54 | `environment` | Een naam, of `{name, url}`. Zet `CI_ENVIRONMENT_NAME` en `CI_ENVIRONMENT_URL`. Geen deployment en geen `on_stop`. |
55 | `interruptible` | Standaard uit. Een nieuwe pipeline op dezelfde ref annuleert oudere jobs die dit aan hebben en nog in de wachtrij staan of lopen. |
55 | `interruptible` | Standaard uit. Een nieuwe pipeline op dezelfde ref annuleert oudere jobs die dit aan hebben en nog in de wachtrij staan of lopen. Zo'n job heet in de UI **Obsolete** (tooltip: canceled because a newer pipeline started for the same ref). |
56 56 | `tags` | Bewaard bij de job. Tags kiezen geen runner; welke runner een job krijgt staat in [runner.md](runner.md). |
57 57 | `extends` | Eén naam of een lijst. Een job waarvan de naam met `.` begint is een sjabloon en draait niet. |
58 58
@@ -138,3 +138,12 @@ Ontbreekt Docker, dan faalt de job met een regel in het log. De time-out is `ci.
138 138 ## Live log
139 139
140 140 De jobpagina vraagt nieuwe regels op zolang de job in de wachtrij staat of loopt, met `?offset=` op het log-adres. Diezelfde poll werkt de wachtrijplek bij zolang de job nog queued is. De console scrolt mee zolang je onderaan staat; scrol je omhoog, dan blijft de plek staan. ANSI-kleuren worden classes. Geheimen van acht tekens of meer zijn `[MASKED]` op het moment dat de regel wordt weggeschreven, ook in die stream.
141
142
143 ## Canceled, Obsolete en timeouts
144
145 - **Obsolete**: een `interruptible` job die stopte omdat een nieuwere pipeline op dezelfde ref startte. De API houdt `status: canceled` (achterwaarts compatibel) en geeft `cancel_reason: superseded` en `display_status: obsolete`. Een pipeline waarvan alle geannuleerde jobs obsolete zijn, toont ook Obsolete.
146 - **Canceled**: handmatig gestopt (knop of `POST …/cancel`), `cancel_reason: manual`. Het joblog eindigt met `canceled by a user`.
147 - **Timeout**: status `failed` met `failure_reason: job_execution_timeout`. Het log eindigt met `Job timed out after <duur> (limit: <bron>)`. De limiet is de `timeout:` van de job, anders `ci.timeout_seconds` van de server (standaard 30 minuten); de runnerinstelling *Maximum job duration* kapt beide af.
148 - Webhook-jobs hebben dezelfde `cancel_reason` en `failure_reason`. Pipeline-events gaan alleen bij geslaagd of mislukt; een geannuleerde of obsolete pipeline stuurt niets.
149 - Bestaande jobs zijn bij de upgrade omgezet: alleen een `interruptible` job met de melding in het log wordt obsolete. Vóór deze versie schreef de runner die melding ook bij handmatig annuleren.
@@ -52,7 +52,7 @@ jobs:
52| `parallel:matrix` | Per lijstitem het cartesisch product, daarna aan elkaar. De job heet `naam: [waarde, waarde]`. De sleutels worden variabelen, in de volgorde uit het bestand. |
52| `parallel:matrix` | Per lijstitem het cartesisch product, daarna aan elkaar. De job heet `naam: [waarde, waarde]`. De sleutels worden variabelen, in de volgorde uit het bestand. |
53| `services` | Sidecar-containers op een eigen Docker-netwerk met de job. Een tekst, of `name`, `alias`, `command`, `entrypoint` en `variables`. Zonder alias is dat het imagenaam zonder registry en tag. |
53| `services` | Sidecar-containers op een eigen Docker-netwerk met de job. Een tekst, of `name`, `alias`, `command`, `entrypoint` en `variables`. Zonder alias is dat het imagenaam zonder registry en tag. |
54| `environment` | Een naam, of `{name, url}`. Zet `CI_ENVIRONMENT_NAME` en `CI_ENVIRONMENT_URL`. Geen deployment en geen `on_stop`. |
54| `environment` | Een naam, of `{name, url}`. Zet `CI_ENVIRONMENT_NAME` en `CI_ENVIRONMENT_URL`. Geen deployment en geen `on_stop`. |
55| `interruptible` | Standaard uit. Een nieuwe pipeline op dezelfde ref annuleert oudere jobs die dit aan hebben en nog in de wachtrij staan of lopen. |
55| `interruptible` | Standaard uit. Een nieuwe pipeline op dezelfde ref annuleert oudere jobs die dit aan hebben en nog in de wachtrij staan of lopen. Zo'n job heet in de UI **Obsolete** (tooltip: canceled because a newer pipeline started for the same ref). |
56| `tags` | Bewaard bij de job. Tags kiezen geen runner; welke runner een job krijgt staat in [runner.md](runner.md). |
56| `tags` | Bewaard bij de job. Tags kiezen geen runner; welke runner een job krijgt staat in [runner.md](runner.md). |
57| `extends` | Eén naam of een lijst. Een job waarvan de naam met `.` begint is een sjabloon en draait niet. |
57| `extends` | Eén naam of een lijst. Een job waarvan de naam met `.` begint is een sjabloon en draait niet. |
58
58
@@ -138,3 +138,12 @@ Ontbreekt Docker, dan faalt de job met een regel in het log. De time-out is `ci.
138## Live log
138## Live log
139
139
140De jobpagina vraagt nieuwe regels op zolang de job in de wachtrij staat of loopt, met `?offset=` op het log-adres. Diezelfde poll werkt de wachtrijplek bij zolang de job nog queued is. De console scrolt mee zolang je onderaan staat; scrol je omhoog, dan blijft de plek staan. ANSI-kleuren worden classes. Geheimen van acht tekens of meer zijn `[MASKED]` op het moment dat de regel wordt weggeschreven, ook in die stream.
140De jobpagina vraagt nieuwe regels op zolang de job in de wachtrij staat of loopt, met `?offset=` op het log-adres. Diezelfde poll werkt de wachtrijplek bij zolang de job nog queued is. De console scrolt mee zolang je onderaan staat; scrol je omhoog, dan blijft de plek staan. ANSI-kleuren worden classes. Geheimen van acht tekens of meer zijn `[MASKED]` op het moment dat de regel wordt weggeschreven, ook in die stream.
141
142
143## Canceled, Obsolete en timeouts
144
145- **Obsolete**: een `interruptible` job die stopte omdat een nieuwere pipeline op dezelfde ref startte. De API houdt `status: canceled` (achterwaarts compatibel) en geeft `cancel_reason: superseded` en `display_status: obsolete`. Een pipeline waarvan alle geannuleerde jobs obsolete zijn, toont ook Obsolete.
146- **Canceled**: handmatig gestopt (knop of `POST …/cancel`), `cancel_reason: manual`. Het joblog eindigt met `canceled by a user`.
147- **Timeout**: status `failed` met `failure_reason: job_execution_timeout`. Het log eindigt met `Job timed out after <duur> (limit: <bron>)`. De limiet is de `timeout:` van de job, anders `ci.timeout_seconds` van de server (standaard 30 minuten); de runnerinstelling *Maximum job duration* kapt beide af.
148- Webhook-jobs hebben dezelfde `cancel_reason` en `failure_reason`. Pipeline-events gaan alleen bij geslaagd of mislukt; een geannuleerde of obsolete pipeline stuurt niets.
149- Bestaande jobs zijn bij de upgrade omgezet: alleen een `interruptible` job met de melding in het log wordt obsolete. Vóór deze versie schreef de runner die melding ook bij handmatig annuleren.
internal/i18n/catalog.go +2 −0
@@ -225,6 +225,8 @@ var en = map[string]string{
225 225 "pipe.manual": "Manual",
226 226 "pipe.skipped": "Skipped",
227 227 "pipe.canceled": "Canceled",
228 "pipe.obsolete": "Obsolete",
229 "pipe.obsolete.tip": "canceled because a newer pipeline started for the same ref",
228 230 "pipe.warning": "Warning",
229 231 "pipe.stage": "Stage",
230 232 "pipe.duration": "Duration",
@@ -225,6 +225,8 @@ var en = map[string]string{
225 "pipe.manual": "Manual",
225 "pipe.manual": "Manual",
226 "pipe.skipped": "Skipped",
226 "pipe.skipped": "Skipped",
227 "pipe.canceled": "Canceled",
227 "pipe.canceled": "Canceled",
228 "pipe.obsolete": "Obsolete",
229 "pipe.obsolete.tip": "canceled because a newer pipeline started for the same ref",
228 "pipe.warning": "Warning",
230 "pipe.warning": "Warning",
229 "pipe.stage": "Stage",
231 "pipe.stage": "Stage",
230 "pipe.duration": "Duration",
232 "pipe.duration": "Duration",
internal/i18n/catalog_lang.go +6 −0
@@ -232,6 +232,8 @@ var nl = map[string]string{
232 232 "pipe.manual": "Handmatig",
233 233 "pipe.skipped": "Overgeslagen",
234 234 "pipe.canceled": "Geannuleerd",
235 "pipe.obsolete": "Verouderd",
236 "pipe.obsolete.tip": "geannuleerd omdat er een nieuwere pipeline voor dezelfde ref startte",
235 237 "pipe.warning": "Waarschuwing",
236 238 "pipe.stage": "Stage",
237 239 "pipe.duration": "Duur",
@@ -876,6 +878,8 @@ var de = map[string]string{
876 878 "pipe.manual": "Manuell",
877 879 "pipe.skipped": "Übersprungen",
878 880 "pipe.canceled": "Abgebrochen",
881 "pipe.obsolete": "Veraltet",
882 "pipe.obsolete.tip": "abgebrochen, weil eine neuere Pipeline für dieselbe Ref gestartet wurde",
879 883 "pipe.warning": "Warnung",
880 884 "pipe.stage": "Stage",
881 885 "pipe.duration": "Dauer",
@@ -1520,6 +1524,8 @@ var fr = map[string]string{
1520 1524 "pipe.manual": "Manuel",
1521 1525 "pipe.skipped": "Ignoré",
1522 1526 "pipe.canceled": "Annulé",
1527 "pipe.obsolete": "Obsolète",
1528 "pipe.obsolete.tip": "annulé car un pipeline plus récent a démarré pour la même ref",
1523 1529 "pipe.warning": "Avertissement",
1524 1530 "pipe.stage": "Stage",
1525 1531 "pipe.duration": "Durée",
@@ -232,6 +232,8 @@ var nl = map[string]string{
232 "pipe.manual": "Handmatig",
232 "pipe.manual": "Handmatig",
233 "pipe.skipped": "Overgeslagen",
233 "pipe.skipped": "Overgeslagen",
234 "pipe.canceled": "Geannuleerd",
234 "pipe.canceled": "Geannuleerd",
235 "pipe.obsolete": "Verouderd",
236 "pipe.obsolete.tip": "geannuleerd omdat er een nieuwere pipeline voor dezelfde ref startte",
235 "pipe.warning": "Waarschuwing",
237 "pipe.warning": "Waarschuwing",
236 "pipe.stage": "Stage",
238 "pipe.stage": "Stage",
237 "pipe.duration": "Duur",
239 "pipe.duration": "Duur",
@@ -876,6 +878,8 @@ var de = map[string]string{
876 "pipe.manual": "Manuell",
878 "pipe.manual": "Manuell",
877 "pipe.skipped": "Übersprungen",
879 "pipe.skipped": "Übersprungen",
878 "pipe.canceled": "Abgebrochen",
880 "pipe.canceled": "Abgebrochen",
881 "pipe.obsolete": "Veraltet",
882 "pipe.obsolete.tip": "abgebrochen, weil eine neuere Pipeline für dieselbe Ref gestartet wurde",
879 "pipe.warning": "Warnung",
883 "pipe.warning": "Warnung",
880 "pipe.stage": "Stage",
884 "pipe.stage": "Stage",
881 "pipe.duration": "Dauer",
885 "pipe.duration": "Dauer",
@@ -1520,6 +1524,8 @@ var fr = map[string]string{
1520 "pipe.manual": "Manuel",
1524 "pipe.manual": "Manuel",
1521 "pipe.skipped": "Ignoré",
1525 "pipe.skipped": "Ignoré",
1522 "pipe.canceled": "Annulé",
1526 "pipe.canceled": "Annulé",
1527 "pipe.obsolete": "Obsolète",
1528 "pipe.obsolete.tip": "annulé car un pipeline plus récent a démarré pour la même ref",
1523 "pipe.warning": "Avertissement",
1529 "pipe.warning": "Avertissement",
1524 "pipe.stage": "Stage",
1530 "pipe.stage": "Stage",
1525 "pipe.duration": "Durée",
1531 "pipe.duration": "Durée",
internal/runner/remote.go +3 −0
@@ -185,6 +185,9 @@ func (r *Runner) RemoteFinish(ctx context.Context, rn store.Runner, jobID int64,
185 185 if strings.Contains(message, "job_execution_timeout") {
186 186 kind = "job_execution_timeout"
187 187 }
188 if kind == "job_execution_timeout" {
189 message = strings.TrimPrefix(message, "job_execution_timeout: ")
190 }
188 191 extra = stamp(ci.Mask(message, mask))
189 192 }
190 193 r.complete(p, job, p, status, extra, kind)
@@ -185,6 +185,9 @@ func (r *Runner) RemoteFinish(ctx context.Context, rn store.Runner, jobID int64,
185 if strings.Contains(message, "job_execution_timeout") {
185 if strings.Contains(message, "job_execution_timeout") {
186 kind = "job_execution_timeout"
186 kind = "job_execution_timeout"
187 }
187 }
188 if kind == "job_execution_timeout" {
189 message = strings.TrimPrefix(message, "job_execution_timeout: ")
190 }
188 extra = stamp(ci.Mask(message, mask))
191 extra = stamp(ci.Mask(message, mask))
189 }
192 }
190 r.complete(p, job, p, status, extra, kind)
193 r.complete(p, job, p, status, extra, kind)
internal/runner/runner.go +22 −10
@@ -62,6 +62,23 @@ func (r *Runner) Interrupt(ids []int64) {
62 62 }
63 63 }
64 64
65 // cancelReason leest waarom een lopende job gestopt werd. CancelJob (door
66 // een gebruiker) zet canceled_by_user al in de database; anders was het
67 // een nieuwere pipeline op dezelfde ref.
68 func (r *Runner) cancelReason(repoID, id int64) string {
69 if j, err := r.Store.JobByID(context.Background(), repoID, id); err == nil && j.Reason == "canceled_by_user" {
70 return j.Reason
71 }
72 return "canceled_by_newer_pipeline"
73 }
74
75 func cancelText(reason string) string {
76 if reason == "canceled_by_user" {
77 return "canceled by a user"
78 }
79 return "canceled because a newer pipeline started for the same ref"
80 }
81
65 82 func (r *Runner) track(id int64, cancel context.CancelFunc) {
66 83 r.cancelMu.Lock()
67 84 defer r.cancelMu.Unlock()
@@ -348,13 +365,7 @@ func (r *Runner) execute(ctx context.Context, p store.Pipeline, job store.Job) {
348 365 stop()
349 366 }()
350 367 runCtx := base
351 limit := r.Timeout
352 if job.Timeout > 0 {
353 limit = job.Timeout
354 }
355 if m := r.controls().timeout; m > 0 && (limit == 0 || time.Duration(m)*time.Minute < limit) {
356 limit = time.Duration(m) * time.Minute
357 }
368 limit, source := EffectiveTimeout(job.Timeout, r.Timeout, r.controls().timeout)
358 369 r.trackStart(job)
359 370 if limit > 0 {
360 371 var cancel context.CancelFunc
@@ -369,11 +380,12 @@ func (r *Runner) execute(ctx context.Context, p store.Pipeline, job store.Job) {
369 380 case err == nil:
370 381 case ctx.Err() == nil && base.Err() != nil:
371 382 status = "canceled"
372 extra = stamp("canceled because a newer pipeline started for the same ref")
383 kind = r.cancelReason(job.RepoID, job.ID)
384 extra = stamp(cancelText(kind))
373 385 case errors.Is(runCtx.Err(), context.DeadlineExceeded):
374 386 status = "failed"
375 387 kind = "job_execution_timeout"
376 extra = stamp(ci.Mask(err.Error(), mask))
388 extra = stamp(TimedOutLine(limit, source))
377 389 default:
378 390 status = "failed"
379 391 kind = classifyFailure(err)
@@ -399,7 +411,7 @@ func (r *Runner) complete(p store.Pipeline, job store.Job, before store.Pipeline
399 411 return
400 412 }
401 413 }
402 if ferr := r.Store.FinishJob(context.Background(), job.ID, status, extra); ferr != nil {
414 if ferr := r.Store.FinishJobReason(context.Background(), job.ID, status, extra, kind); ferr != nil {
403 415 r.Log.Error("job afronden", "err", ferr)
404 416 }
405 417 r.settle(context.Background(), p.ID)
@@ -62,6 +62,23 @@ func (r *Runner) Interrupt(ids []int64) {
62 }
62 }
63}
63}
64
64
65// cancelReason leest waarom een lopende job gestopt werd. CancelJob (door
66// een gebruiker) zet canceled_by_user al in de database; anders was het
67// een nieuwere pipeline op dezelfde ref.
68func (r *Runner) cancelReason(repoID, id int64) string {
69 if j, err := r.Store.JobByID(context.Background(), repoID, id); err == nil && j.Reason == "canceled_by_user" {
70 return j.Reason
71 }
72 return "canceled_by_newer_pipeline"
73}
74
75func cancelText(reason string) string {
76 if reason == "canceled_by_user" {
77 return "canceled by a user"
78 }
79 return "canceled because a newer pipeline started for the same ref"
80}
81
65func (r *Runner) track(id int64, cancel context.CancelFunc) {
82func (r *Runner) track(id int64, cancel context.CancelFunc) {
66 r.cancelMu.Lock()
83 r.cancelMu.Lock()
67 defer r.cancelMu.Unlock()
84 defer r.cancelMu.Unlock()
@@ -348,13 +365,7 @@ func (r *Runner) execute(ctx context.Context, p store.Pipeline, job store.Job) {
348 stop()
365 stop()
349 }()
366 }()
350 runCtx := base
367 runCtx := base
351 limit := r.Timeout
368 limit, source := EffectiveTimeout(job.Timeout, r.Timeout, r.controls().timeout)
352 if job.Timeout > 0 {
353 limit = job.Timeout
354 }
355 if m := r.controls().timeout; m > 0 && (limit == 0 || time.Duration(m)*time.Minute < limit) {
356 limit = time.Duration(m) * time.Minute
357 }
358 r.trackStart(job)
369 r.trackStart(job)
359 if limit > 0 {
370 if limit > 0 {
360 var cancel context.CancelFunc
371 var cancel context.CancelFunc
@@ -369,11 +380,12 @@ func (r *Runner) execute(ctx context.Context, p store.Pipeline, job store.Job) {
369 case err == nil:
380 case err == nil:
370 case ctx.Err() == nil && base.Err() != nil:
381 case ctx.Err() == nil && base.Err() != nil:
371 status = "canceled"
382 status = "canceled"
372 extra = stamp("canceled because a newer pipeline started for the same ref")
383 kind = r.cancelReason(job.RepoID, job.ID)
384 extra = stamp(cancelText(kind))
373 case errors.Is(runCtx.Err(), context.DeadlineExceeded):
385 case errors.Is(runCtx.Err(), context.DeadlineExceeded):
374 status = "failed"
386 status = "failed"
375 kind = "job_execution_timeout"
387 kind = "job_execution_timeout"
376 extra = stamp(ci.Mask(err.Error(), mask))
388 extra = stamp(TimedOutLine(limit, source))
377 default:
389 default:
378 status = "failed"
390 status = "failed"
379 kind = classifyFailure(err)
391 kind = classifyFailure(err)
@@ -399,7 +411,7 @@ func (r *Runner) complete(p store.Pipeline, job store.Job, before store.Pipeline
399 return
411 return
400 }
412 }
401 }
413 }
402 if ferr := r.Store.FinishJob(context.Background(), job.ID, status, extra); ferr != nil {
414 if ferr := r.Store.FinishJobReason(context.Background(), job.ID, status, extra, kind); ferr != nil {
403 r.Log.Error("job afronden", "err", ferr)
415 r.Log.Error("job afronden", "err", ferr)
404 }
416 }
405 r.settle(context.Background(), p.ID)
417 r.settle(context.Background(), p.ID)
internal/runner/timeout.go added +65 −0
@@ -0,0 +1,65 @@
1 package runner
2
3 import (
4 "fmt"
5 "time"
6 )
7
8 // Bronnen van de effectieve timeout.
9 const (
10 TimeoutFromJob = "job" // timeout: in blue-ci-cd.yml (of default:)
11 TimeoutFromRunner = "runner" // Maximum job duration van de runner
12 TimeoutFromServer = "server" // ci.timeout_seconds in de serverconfig
13 )
14
15 // EffectiveTimeout bepaalt de limiet van een job, zoals execute die altijd
16 // al rekende: de job zelf, anders de serverstandaard; het runner-maximum
17 // (minuten, 0 = geen) kapt beide af.
18 func EffectiveTimeout(job, server time.Duration, runnerMaxMin int) (limit time.Duration, source string) {
19 limit, source = server, TimeoutFromServer
20 if job > 0 {
21 limit, source = job, TimeoutFromJob
22 }
23 if runnerMaxMin > 0 {
24 m := time.Duration(runnerMaxMin) * time.Minute
25 if limit == 0 || m < limit {
26 limit, source = m, TimeoutFromRunner
27 }
28 }
29 return limit, source
30 }
31
32 // TimeoutSourceText is de Engelse uitleg van een bron voor log en API.
33 func TimeoutSourceText(source string) string {
34 switch source {
35 case TimeoutFromJob:
36 return "timeout in blue-ci-cd.yml"
37 case TimeoutFromRunner:
38 return "runner maximum job duration"
39 case TimeoutFromServer:
40 return "server default (ci.timeout_seconds)"
41 }
42 return source
43 }
44
45 // TimedOutLine is de logregel als een job zijn limiet haalt.
46 func TimedOutLine(limit time.Duration, source string) string {
47 return fmt.Sprintf("Job timed out after %s (limit: %s)", FormatLimit(limit), TimeoutSourceText(source))
48 }
49
50 // FormatLimit schrijft een duur als 3h, 1h30m of 45m.
51 func FormatLimit(d time.Duration) string {
52 d = d.Round(time.Second)
53 h, m, s := int(d/time.Hour), int(d%time.Hour/time.Minute), int(d%time.Minute/time.Second)
54 out := ""
55 if h > 0 {
56 out += fmt.Sprintf("%dh", h)
57 }
58 if m > 0 {
59 out += fmt.Sprintf("%dm", m)
60 }
61 if s > 0 || out == "" {
62 out += fmt.Sprintf("%ds", s)
63 }
64 return out
65 }
@@ -0,0 +1,65 @@
1package runner
2
3import (
4 "fmt"
5 "time"
6)
7
8// Bronnen van de effectieve timeout.
9const (
10 TimeoutFromJob = "job" // timeout: in blue-ci-cd.yml (of default:)
11 TimeoutFromRunner = "runner" // Maximum job duration van de runner
12 TimeoutFromServer = "server" // ci.timeout_seconds in de serverconfig
13)
14
15// EffectiveTimeout bepaalt de limiet van een job, zoals execute die altijd
16// al rekende: de job zelf, anders de serverstandaard; het runner-maximum
17// (minuten, 0 = geen) kapt beide af.
18func EffectiveTimeout(job, server time.Duration, runnerMaxMin int) (limit time.Duration, source string) {
19 limit, source = server, TimeoutFromServer
20 if job > 0 {
21 limit, source = job, TimeoutFromJob
22 }
23 if runnerMaxMin > 0 {
24 m := time.Duration(runnerMaxMin) * time.Minute
25 if limit == 0 || m < limit {
26 limit, source = m, TimeoutFromRunner
27 }
28 }
29 return limit, source
30}
31
32// TimeoutSourceText is de Engelse uitleg van een bron voor log en API.
33func TimeoutSourceText(source string) string {
34 switch source {
35 case TimeoutFromJob:
36 return "timeout in blue-ci-cd.yml"
37 case TimeoutFromRunner:
38 return "runner maximum job duration"
39 case TimeoutFromServer:
40 return "server default (ci.timeout_seconds)"
41 }
42 return source
43}
44
45// TimedOutLine is de logregel als een job zijn limiet haalt.
46func TimedOutLine(limit time.Duration, source string) string {
47 return fmt.Sprintf("Job timed out after %s (limit: %s)", FormatLimit(limit), TimeoutSourceText(source))
48}
49
50// FormatLimit schrijft een duur als 3h, 1h30m of 45m.
51func FormatLimit(d time.Duration) string {
52 d = d.Round(time.Second)
53 h, m, s := int(d/time.Hour), int(d%time.Hour/time.Minute), int(d%time.Minute/time.Second)
54 out := ""
55 if h > 0 {
56 out += fmt.Sprintf("%dh", h)
57 }
58 if m > 0 {
59 out += fmt.Sprintf("%dm", m)
60 }
61 if s > 0 || out == "" {
62 out += fmt.Sprintf("%ds", s)
63 }
64 return out
65}
internal/runner/timeout_test.go added +33 −0
@@ -0,0 +1,33 @@
1 package runner
2
3 import (
4 "testing"
5 "time"
6 )
7
8 func TestEffectiveTimeout(t *testing.T) {
9 cases := []struct {
10 job, server time.Duration
11 cap int
12 want time.Duration
13 src string
14 }{
15 {0, 30 * time.Minute, 0, 30 * time.Minute, TimeoutFromServer},
16 {3 * time.Hour, 30 * time.Minute, 0, 3 * time.Hour, TimeoutFromJob},
17 {3 * time.Hour, 30 * time.Minute, 60, time.Hour, TimeoutFromRunner},
18 {10 * time.Minute, 30 * time.Minute, 60, 10 * time.Minute, TimeoutFromJob},
19 {0, 0, 0, 0, TimeoutFromServer},
20 }
21 for _, c := range cases {
22 got, src := EffectiveTimeout(c.job, c.server, c.cap)
23 if got != c.want || src != c.src {
24 t.Fatalf("%v/%v/%d: %v %s", c.job, c.server, c.cap, got, src)
25 }
26 }
27 if l := TimedOutLine(3*time.Hour, TimeoutFromJob); l != "Job timed out after 3h (limit: timeout in blue-ci-cd.yml)" {
28 t.Fatal(l)
29 }
30 if FormatLimit(90*time.Minute) != "1h30m" {
31 t.Fatal(FormatLimit(90 * time.Minute))
32 }
33 }
@@ -0,0 +1,33 @@
1package runner
2
3import (
4 "testing"
5 "time"
6)
7
8func TestEffectiveTimeout(t *testing.T) {
9 cases := []struct {
10 job, server time.Duration
11 cap int
12 want time.Duration
13 src string
14 }{
15 {0, 30 * time.Minute, 0, 30 * time.Minute, TimeoutFromServer},
16 {3 * time.Hour, 30 * time.Minute, 0, 3 * time.Hour, TimeoutFromJob},
17 {3 * time.Hour, 30 * time.Minute, 60, time.Hour, TimeoutFromRunner},
18 {10 * time.Minute, 30 * time.Minute, 60, 10 * time.Minute, TimeoutFromJob},
19 {0, 0, 0, 0, TimeoutFromServer},
20 }
21 for _, c := range cases {
22 got, src := EffectiveTimeout(c.job, c.server, c.cap)
23 if got != c.want || src != c.src {
24 t.Fatalf("%v/%v/%d: %v %s", c.job, c.server, c.cap, got, src)
25 }
26 }
27 if l := TimedOutLine(3*time.Hour, TimeoutFromJob); l != "Job timed out after 3h (limit: timeout in blue-ci-cd.yml)" {
28 t.Fatal(l)
29 }
30 if FormatLimit(90*time.Minute) != "1h30m" {
31 t.Fatal(FormatLimit(90 * time.Minute))
32 }
33}
internal/server/api_flow.go +30 −3
@@ -346,11 +346,38 @@ func (s *Server) pipeJSON(repo store.Repo, p store.Pipeline) map[string]any {
346 346 }
347 347 }
348 348
349 // pipeJSONJobs is pipeJSON met cancel_reason en display_status, die de
350 // jobs nodig hebben. status blijft canceled voor oude clients.
351 func (s *Server) pipeJSONJobs(ctx context.Context, repo store.Repo, p store.Pipeline) map[string]any {
352 out := s.pipeJSON(repo, p)
353 st := s.pipeStatusFor(p)
354 out["display_status"] = st
355 out["cancel_reason"] = nil
356 if st == "canceled" {
357 jobs, _ := s.Store.JobsByPipeline(ctx, p.ID)
358 out["cancel_reason"] = "manual"
359 if store.PipelineObsolete(jobs) {
360 out["cancel_reason"] = "superseded"
361 out["display_status"] = "obsolete"
362 }
363 }
364 return out
365 }
366
349 367 func (s *Server) jobJSON(ctx context.Context, j store.Job) map[string]any {
350 368 out := map[string]any{
351 369 "id": j.ID, "name": j.Name, "stage": j.Stage, "status": j.Status, "when": j.When,
352 370 "allow_failure": j.AllowFailure, "started_at": rfcTime(j.StartedAt), "finished_at": rfcTime(j.FinishedAt),
353 "runner": nil,
371 "runner": nil, "display_status": j.Status, "cancel_reason": nil, "failure_reason": nil,
372 }
373 if r := j.CancelReason(); r != "" {
374 out["cancel_reason"] = r
375 if j.Obsolete() {
376 out["display_status"] = "obsolete"
377 }
378 }
379 if r := j.FailureReason(); r != "" {
380 out["failure_reason"] = r
354 381 }
355 382 if jr := s.Store.JobRun(ctx, j.ID); jr.RunnerName != "" {
356 383 kind := "builtin"
@@ -399,7 +426,7 @@ func (s *Server) apiPipelines(w http.ResponseWriter, r *http.Request) {
399 426 page, per := pageQuery(r)
400 427 rows := make([]map[string]any, 0, len(list))
401 428 for _, p := range list {
402 rows = append(rows, s.pipeJSON(repo, p))
429 rows = append(rows, s.pipeJSONJobs(r.Context(), repo, p))
403 430 }
404 431 writePage(w, r, slicePage(rows, page, per), len(rows), page, per)
405 432 }
@@ -419,7 +446,7 @@ func (s *Server) apiPipeline(w http.ResponseWriter, r *http.Request) {
419 446 s.writeAPIErr(w, r, notFound(err))
420 447 return
421 448 }
422 writeJSON(w, http.StatusOK, s.pipeJSON(repo, p))
449 writeJSON(w, http.StatusOK, s.pipeJSONJobs(r.Context(), repo, p))
423 450 }
424 451
425 452 func (s *Server) apiRetryPipeline(w http.ResponseWriter, r *http.Request) {
@@ -346,11 +346,38 @@ func (s *Server) pipeJSON(repo store.Repo, p store.Pipeline) map[string]any {
346 }
346 }
347}
347}
348
348
349// pipeJSONJobs is pipeJSON met cancel_reason en display_status, die de
350// jobs nodig hebben. status blijft canceled voor oude clients.
351func (s *Server) pipeJSONJobs(ctx context.Context, repo store.Repo, p store.Pipeline) map[string]any {
352 out := s.pipeJSON(repo, p)
353 st := s.pipeStatusFor(p)
354 out["display_status"] = st
355 out["cancel_reason"] = nil
356 if st == "canceled" {
357 jobs, _ := s.Store.JobsByPipeline(ctx, p.ID)
358 out["cancel_reason"] = "manual"
359 if store.PipelineObsolete(jobs) {
360 out["cancel_reason"] = "superseded"
361 out["display_status"] = "obsolete"
362 }
363 }
364 return out
365}
366
349func (s *Server) jobJSON(ctx context.Context, j store.Job) map[string]any {
367func (s *Server) jobJSON(ctx context.Context, j store.Job) map[string]any {
350 out := map[string]any{
368 out := map[string]any{
351 "id": j.ID, "name": j.Name, "stage": j.Stage, "status": j.Status, "when": j.When,
369 "id": j.ID, "name": j.Name, "stage": j.Stage, "status": j.Status, "when": j.When,
352 "allow_failure": j.AllowFailure, "started_at": rfcTime(j.StartedAt), "finished_at": rfcTime(j.FinishedAt),
370 "allow_failure": j.AllowFailure, "started_at": rfcTime(j.StartedAt), "finished_at": rfcTime(j.FinishedAt),
353 "runner": nil,
371 "runner": nil, "display_status": j.Status, "cancel_reason": nil, "failure_reason": nil,
372 }
373 if r := j.CancelReason(); r != "" {
374 out["cancel_reason"] = r
375 if j.Obsolete() {
376 out["display_status"] = "obsolete"
377 }
378 }
379 if r := j.FailureReason(); r != "" {
380 out["failure_reason"] = r
354 }
381 }
355 if jr := s.Store.JobRun(ctx, j.ID); jr.RunnerName != "" {
382 if jr := s.Store.JobRun(ctx, j.ID); jr.RunnerName != "" {
356 kind := "builtin"
383 kind := "builtin"
@@ -399,7 +426,7 @@ func (s *Server) apiPipelines(w http.ResponseWriter, r *http.Request) {
399 page, per := pageQuery(r)
426 page, per := pageQuery(r)
400 rows := make([]map[string]any, 0, len(list))
427 rows := make([]map[string]any, 0, len(list))
401 for _, p := range list {
428 for _, p := range list {
402 rows = append(rows, s.pipeJSON(repo, p))
429 rows = append(rows, s.pipeJSONJobs(r.Context(), repo, p))
403 }
430 }
404 writePage(w, r, slicePage(rows, page, per), len(rows), page, per)
431 writePage(w, r, slicePage(rows, page, per), len(rows), page, per)
405}
432}
@@ -419,7 +446,7 @@ func (s *Server) apiPipeline(w http.ResponseWriter, r *http.Request) {
419 s.writeAPIErr(w, r, notFound(err))
446 s.writeAPIErr(w, r, notFound(err))
420 return
447 return
421 }
448 }
422 writeJSON(w, http.StatusOK, s.pipeJSON(repo, p))
449 writeJSON(w, http.StatusOK, s.pipeJSONJobs(r.Context(), repo, p))
423}
450}
424
451
425func (s *Server) apiRetryPipeline(w http.ResponseWriter, r *http.Request) {
452func (s *Server) apiRetryPipeline(w http.ResponseWriter, r *http.Request) {
internal/server/api_openapi.go +23 −18
@@ -228,16 +228,18 @@ func apiSchemas() map[string]any {
228 228 "body": str("Note text, including optional quick actions."),
229 229 }),
230 230 "Pipeline": obj("Pipeline.", map[string]any{
231 "id": integer("Pipeline id."),
232 "sha": str("Commit SHA."),
233 "ref": str("Git ref, for example refs/heads/master."),
234 "status": str("Pipeline status."),
235 "source": str("Trigger source."),
236 "actor": str("Username that started the pipeline."),
237 "created_at": when,
238 "started_at": when,
239 "finished_at": when,
240 "web_url": str("Full page URL. An empty base URL yields a path."),
231 "id": integer("Pipeline id."),
232 "sha": str("Commit SHA."),
233 "ref": str("Git ref, for example refs/heads/master."),
234 "status": str("Pipeline status. A pipeline stopped by a newer pipeline stays canceled; see cancel_reason."),
235 "display_status": str("Status as the UI shows it: obsolete when every canceled job was superseded by a newer pipeline on the same ref, otherwise equal to status. Only in list and get responses."),
236 "cancel_reason": str("For status canceled: superseded (a newer pipeline started for the same ref) or manual. Null otherwise. Only in list and get responses."),
237 "source": str("Trigger source."),
238 "actor": str("Username that started the pipeline."),
239 "created_at": when,
240 "started_at": when,
241 "finished_at": when,
242 "web_url": str("Full page URL. An empty base URL yields a path."),
241 243 }),
242 244 "PipelineCreate": obj("Start a pipeline.", map[string]any{
243 245 "ref": str("Branch, tag or full ref to run."),
@@ -250,14 +252,17 @@ func apiSchemas() map[string]any {
250 252 },
251 253 }),
252 254 "Job": obj("CI job.", map[string]any{
253 "id": integer("Job id."),
254 "name": str("Job name."),
255 "stage": str("Stage name."),
256 "status": str("Job status."),
257 "when": str("When the job runs."),
258 "allow_failure": boolean("A failed job does not fail the pipeline."),
259 "started_at": when,
260 "finished_at": when,
255 "id": integer("Job id."),
256 "name": str("Job name."),
257 "stage": str("Stage name."),
258 "status": str("Job status."),
259 "when": str("When the job runs."),
260 "display_status": str("Status as the UI shows it: obsolete for a job canceled because a newer pipeline started for the same ref, otherwise equal to status."),
261 "cancel_reason": str("For status canceled: superseded or manual. Null otherwise."),
262 "failure_reason": str("For status failed: job_execution_timeout, script_failure or runner_system_failure when known. Null otherwise."),
263 "allow_failure": boolean("A failed job does not fail the pipeline."),
264 "started_at": when,
265 "finished_at": when,
261 266 }),
262 267 "Branch": obj("Branch tip. Create and rename responses only include name.", map[string]any{
263 268 "name": str("Branch name."),
@@ -228,16 +228,18 @@ func apiSchemas() map[string]any {
228 "body": str("Note text, including optional quick actions."),
228 "body": str("Note text, including optional quick actions."),
229 }),
229 }),
230 "Pipeline": obj("Pipeline.", map[string]any{
230 "Pipeline": obj("Pipeline.", map[string]any{
231 "id": integer("Pipeline id."),
231 "id": integer("Pipeline id."),
232 "sha": str("Commit SHA."),
232 "sha": str("Commit SHA."),
233 "ref": str("Git ref, for example refs/heads/master."),
233 "ref": str("Git ref, for example refs/heads/master."),
234 "status": str("Pipeline status."),
234 "status": str("Pipeline status. A pipeline stopped by a newer pipeline stays canceled; see cancel_reason."),
235 "source": str("Trigger source."),
235 "display_status": str("Status as the UI shows it: obsolete when every canceled job was superseded by a newer pipeline on the same ref, otherwise equal to status. Only in list and get responses."),
236 "actor": str("Username that started the pipeline."),
236 "cancel_reason": str("For status canceled: superseded (a newer pipeline started for the same ref) or manual. Null otherwise. Only in list and get responses."),
237 "created_at": when,
237 "source": str("Trigger source."),
238 "started_at": when,
238 "actor": str("Username that started the pipeline."),
239 "finished_at": when,
239 "created_at": when,
240 "web_url": str("Full page URL. An empty base URL yields a path."),
240 "started_at": when,
241 "finished_at": when,
242 "web_url": str("Full page URL. An empty base URL yields a path."),
241 }),
243 }),
242 "PipelineCreate": obj("Start a pipeline.", map[string]any{
244 "PipelineCreate": obj("Start a pipeline.", map[string]any{
243 "ref": str("Branch, tag or full ref to run."),
245 "ref": str("Branch, tag or full ref to run."),
@@ -250,14 +252,17 @@ func apiSchemas() map[string]any {
250 },
252 },
251 }),
253 }),
252 "Job": obj("CI job.", map[string]any{
254 "Job": obj("CI job.", map[string]any{
253 "id": integer("Job id."),
255 "id": integer("Job id."),
254 "name": str("Job name."),
256 "name": str("Job name."),
255 "stage": str("Stage name."),
257 "stage": str("Stage name."),
256 "status": str("Job status."),
258 "status": str("Job status."),
257 "when": str("When the job runs."),
259 "when": str("When the job runs."),
258 "allow_failure": boolean("A failed job does not fail the pipeline."),
260 "display_status": str("Status as the UI shows it: obsolete for a job canceled because a newer pipeline started for the same ref, otherwise equal to status."),
259 "started_at": when,
261 "cancel_reason": str("For status canceled: superseded or manual. Null otherwise."),
260 "finished_at": when,
262 "failure_reason": str("For status failed: job_execution_timeout, script_failure or runner_system_failure when known. Null otherwise."),
263 "allow_failure": boolean("A failed job does not fail the pipeline."),
264 "started_at": when,
265 "finished_at": when,
261 }),
266 }),
262 "Branch": obj("Branch tip. Create and rename responses only include name.", map[string]any{
267 "Branch": obj("Branch tip. Create and rename responses only include name.", map[string]any{
263 "name": str("Branch name."),
268 "name": str("Branch name."),
internal/server/hook_payload.go +1 −0
@@ -84,6 +84,7 @@ func (s *Server) fillPipelineEvent(ctx context.Context, repo store.Repo, ev *web
84 84 WebURL: pipeURL + "/jobs/" + strconv.FormatInt(j.ID, 10),
85 85 Log: logText,
86 86 LogTruncated: truncated,
87 CancelReason: j.CancelReason(), FailureReason: j.FailureReason(),
87 88 }
88 89 if truncated {
89 90 info.LogURL = jobLogAPIURL(s.Cfg.BaseURL, repo, j.ID)
@@ -84,6 +84,7 @@ func (s *Server) fillPipelineEvent(ctx context.Context, repo store.Repo, ev *web
84 WebURL: pipeURL + "/jobs/" + strconv.FormatInt(j.ID, 10),
84 WebURL: pipeURL + "/jobs/" + strconv.FormatInt(j.ID, 10),
85 Log: logText,
85 Log: logText,
86 LogTruncated: truncated,
86 LogTruncated: truncated,
87 CancelReason: j.CancelReason(), FailureReason: j.FailureReason(),
87 }
88 }
88 if truncated {
89 if truncated {
89 info.LogURL = jobLogAPIURL(s.Cfg.BaseURL, repo, j.ID)
90 info.LogURL = jobLogAPIURL(s.Cfg.BaseURL, repo, j.ID)
internal/server/obsolete_test.go added +24 −0
@@ -0,0 +1,24 @@
1 package server
2
3 import (
4 "testing"
5
6 "gitlab.com/Timfa/bluegit/internal/store"
7 )
8
9 func TestObsoleteDisplay(t *testing.T) {
10 sup := store.Job{Status: "canceled", Reason: store.ReasonSuperseded}
11 man := store.Job{Status: "canceled", Reason: store.ReasonManual}
12 if jobDisplay(sup) != "obsolete" || jobDisplay(man) != "canceled" {
13 t.Fatal("job")
14 }
15 if displayStatus("canceled", []store.Job{sup, {Status: "success"}}) != "obsolete" {
16 t.Fatal("pipeline obsolete")
17 }
18 if displayStatus("canceled", []store.Job{sup, man}) != "canceled" {
19 t.Fatal("gemengd blijft canceled")
20 }
21 if stageStatus([]store.Job{sup}) != "obsolete" || stageStatus([]store.Job{man}) != "canceled" {
22 t.Fatal("stage")
23 }
24 }
@@ -0,0 +1,24 @@
1package server
2
3import (
4 "testing"
5
6 "gitlab.com/Timfa/bluegit/internal/store"
7)
8
9func TestObsoleteDisplay(t *testing.T) {
10 sup := store.Job{Status: "canceled", Reason: store.ReasonSuperseded}
11 man := store.Job{Status: "canceled", Reason: store.ReasonManual}
12 if jobDisplay(sup) != "obsolete" || jobDisplay(man) != "canceled" {
13 t.Fatal("job")
14 }
15 if displayStatus("canceled", []store.Job{sup, {Status: "success"}}) != "obsolete" {
16 t.Fatal("pipeline obsolete")
17 }
18 if displayStatus("canceled", []store.Job{sup, man}) != "canceled" {
19 t.Fatal("gemengd blijft canceled")
20 }
21 if stageStatus([]store.Job{sup}) != "obsolete" || stageStatus([]store.Job{man}) != "canceled" {
22 t.Fatal("stage")
23 }
24}
internal/server/pipeline_page.go +14 −1
@@ -264,6 +264,9 @@ func displayStatus(pipe string, jobs []store.Job) string {
264 264 case "queued":
265 265 return "pending"
266 266 case "canceled":
267 if store.PipelineObsolete(jobs) {
268 return "obsolete"
269 }
267 270 return "canceled"
268 271 case "waiting_for_update":
269 272 return "waiting_for_update"
@@ -308,7 +311,11 @@ func stageViews(jobs []store.Job, ranks map[int64]int, tr func(string, ...any) s
308 311 Queue: queueText(tr, ranks, j.ID),
309 312 })
310 313 }
311 out = append(out, StageView{Name: name, Status: status, Label: label, Tip: name + ": " + strings.ToLower(label), Jobs: links})
314 stip := name + ": " + strings.ToLower(label)
315 if status == "obsolete" {
316 stip += " (" + tr("pipe.obsolete.tip") + ")"
317 }
318 out = append(out, StageView{Name: name, Status: status, Label: label, Tip: stip, Jobs: links})
312 319 }
313 320 return out
314 321 }
@@ -341,6 +348,9 @@ func stageStatus(jobs []store.Job) string {
341 348 return "failed"
342 349 }
343 350 if canceled {
351 if store.PipelineObsolete(jobs) {
352 return "obsolete"
353 }
344 354 return "canceled"
345 355 }
346 356 if warning {
@@ -365,6 +375,9 @@ func jobDisplay(j store.Job) string {
365 375 if j.Status == "failed" && j.AllowFailure {
366 376 return "warning"
367 377 }
378 if j.Obsolete() {
379 return "obsolete"
380 }
368 381 switch j.Status {
369 382 case "success":
370 383 return "passed"
@@ -264,6 +264,9 @@ func displayStatus(pipe string, jobs []store.Job) string {
264 case "queued":
264 case "queued":
265 return "pending"
265 return "pending"
266 case "canceled":
266 case "canceled":
267 if store.PipelineObsolete(jobs) {
268 return "obsolete"
269 }
267 return "canceled"
270 return "canceled"
268 case "waiting_for_update":
271 case "waiting_for_update":
269 return "waiting_for_update"
272 return "waiting_for_update"
@@ -308,7 +311,11 @@ func stageViews(jobs []store.Job, ranks map[int64]int, tr func(string, ...any) s
308 Queue: queueText(tr, ranks, j.ID),
311 Queue: queueText(tr, ranks, j.ID),
309 })
312 })
310 }
313 }
311 out = append(out, StageView{Name: name, Status: status, Label: label, Tip: name + ": " + strings.ToLower(label), Jobs: links})
314 stip := name + ": " + strings.ToLower(label)
315 if status == "obsolete" {
316 stip += " (" + tr("pipe.obsolete.tip") + ")"
317 }
318 out = append(out, StageView{Name: name, Status: status, Label: label, Tip: stip, Jobs: links})
312 }
319 }
313 return out
320 return out
314}
321}
@@ -341,6 +348,9 @@ func stageStatus(jobs []store.Job) string {
341 return "failed"
348 return "failed"
342 }
349 }
343 if canceled {
350 if canceled {
351 if store.PipelineObsolete(jobs) {
352 return "obsolete"
353 }
344 return "canceled"
354 return "canceled"
345 }
355 }
346 if warning {
356 if warning {
@@ -365,6 +375,9 @@ func jobDisplay(j store.Job) string {
365 if j.Status == "failed" && j.AllowFailure {
375 if j.Status == "failed" && j.AllowFailure {
366 return "warning"
376 return "warning"
367 }
377 }
378 if j.Obsolete() {
379 return "obsolete"
380 }
368 switch j.Status {
381 switch j.Status {
369 case "success":
382 case "success":
370 return "passed"
383 return "passed"
internal/server/static/float.js +31 −0
@@ -307,3 +307,34 @@
307 307 });
308 308 });
309 309 })();
310
311 // Obsolete-statussen krijgen hun uitleg als tooltip (data-tip) en
312 // aria-label, ook als pipeline.js de klasse live wijzigt.
313 (function () {
314 var tip = document.body.getAttribute("data-obsolete-tip") || "canceled because a newer pipeline started for the same ref";
315 function tag(root) {
316 var list = (root || document).querySelectorAll(".status.obsolete");
317 Array.prototype.forEach.call(list, function (el) {
318 if (el.getAttribute("data-tip") !== tip) {
319 el.setAttribute("data-tip", tip);
320 var label = (el.textContent || "").trim();
321 el.setAttribute("aria-label", label ? label + ": " + tip : tip);
322 }
323 });
324 }
325 function untag(el) {
326 if (el.classList && el.classList.contains("status") && !el.classList.contains("obsolete") && el.getAttribute("data-tip") === tip) {
327 el.removeAttribute("data-tip");
328 el.removeAttribute("aria-label");
329 }
330 }
331 tag();
332 new MutationObserver(function (muts) {
333 muts.forEach(function (m) {
334 if (m.type === "attributes") {
335 untag(m.target);
336 }
337 });
338 tag();
339 }).observe(document.body, { subtree: true, childList: true, attributes: true, attributeFilter: ["class"] });
340 })();
@@ -307,3 +307,34 @@
307 });
307 });
308 });
308 });
309})();
309})();
310
311// Obsolete-statussen krijgen hun uitleg als tooltip (data-tip) en
312// aria-label, ook als pipeline.js de klasse live wijzigt.
313(function () {
314 var tip = document.body.getAttribute("data-obsolete-tip") || "canceled because a newer pipeline started for the same ref";
315 function tag(root) {
316 var list = (root || document).querySelectorAll(".status.obsolete");
317 Array.prototype.forEach.call(list, function (el) {
318 if (el.getAttribute("data-tip") !== tip) {
319 el.setAttribute("data-tip", tip);
320 var label = (el.textContent || "").trim();
321 el.setAttribute("aria-label", label ? label + ": " + tip : tip);
322 }
323 });
324 }
325 function untag(el) {
326 if (el.classList && el.classList.contains("status") && !el.classList.contains("obsolete") && el.getAttribute("data-tip") === tip) {
327 el.removeAttribute("data-tip");
328 el.removeAttribute("aria-label");
329 }
330 }
331 tag();
332 new MutationObserver(function (muts) {
333 muts.forEach(function (m) {
334 if (m.type === "attributes") {
335 untag(m.target);
336 }
337 });
338 tag();
339 }).observe(document.body, { subtree: true, childList: true, attributes: true, attributeFilter: ["class"] });
340})();
internal/server/static/style.css +5 −0
@@ -631,12 +631,17 @@ svg.ico { width: 14px; height: 14px; flex: none; }
631 631 .status.warning { background: #fff4e0; color: #8a5a00; }
632 632 .status.running { background: #e7f0ff; color: #1f6feb; }
633 633 .status.canceled { background: #f3f0f0; color: #57606a; }
634 .status.obsolete { background: #f4f5f7; color: #8c959f; font-weight: 600; }
634 635 .mark { position: relative; width: 16px; height: 16px; border-radius: 50%; display: inline-block; flex: none; background: #8c959f; }
635 636 .status.passed .mark, .stage-dot.passed .mark { background: #1aaa55; }
636 637 .status.failed .mark, .stage-dot.failed .mark { background: #dd2b0e; }
637 638 .status.warning .mark, .stage-dot.warning .mark { background: #c17d10; }
638 639 .status.running .mark, .stage-dot.running .mark { background: #1f75cb; }
639 640 .status.canceled .mark, .stage-dot.canceled .mark { background: #8c959f; }
641 .status.obsolete .mark, .stage-dot.obsolete .mark { background: transparent; box-shadow: inset 0 0 0 2px #afb8c1; }
642 .obsolete .mark::after {
643 content: ""; position: absolute; left: 3px; top: 7px; width: 10px; height: 2px; background: #afb8c1; transform: rotate(-45deg);
644 }
640 645 .passed .mark::after {
641 646 content: ""; position: absolute; left: 5px; top: 2px; width: 4px; height: 8px;
642 647 border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
@@ -631,12 +631,17 @@ svg.ico { width: 14px; height: 14px; flex: none; }
631.status.warning { background: #fff4e0; color: #8a5a00; }
631.status.warning { background: #fff4e0; color: #8a5a00; }
632.status.running { background: #e7f0ff; color: #1f6feb; }
632.status.running { background: #e7f0ff; color: #1f6feb; }
633.status.canceled { background: #f3f0f0; color: #57606a; }
633.status.canceled { background: #f3f0f0; color: #57606a; }
634.status.obsolete { background: #f4f5f7; color: #8c959f; font-weight: 600; }
634.mark { position: relative; width: 16px; height: 16px; border-radius: 50%; display: inline-block; flex: none; background: #8c959f; }
635.mark { position: relative; width: 16px; height: 16px; border-radius: 50%; display: inline-block; flex: none; background: #8c959f; }
635.status.passed .mark, .stage-dot.passed .mark { background: #1aaa55; }
636.status.passed .mark, .stage-dot.passed .mark { background: #1aaa55; }
636.status.failed .mark, .stage-dot.failed .mark { background: #dd2b0e; }
637.status.failed .mark, .stage-dot.failed .mark { background: #dd2b0e; }
637.status.warning .mark, .stage-dot.warning .mark { background: #c17d10; }
638.status.warning .mark, .stage-dot.warning .mark { background: #c17d10; }
638.status.running .mark, .stage-dot.running .mark { background: #1f75cb; }
639.status.running .mark, .stage-dot.running .mark { background: #1f75cb; }
639.status.canceled .mark, .stage-dot.canceled .mark { background: #8c959f; }
640.status.canceled .mark, .stage-dot.canceled .mark { background: #8c959f; }
641.status.obsolete .mark, .stage-dot.obsolete .mark { background: transparent; box-shadow: inset 0 0 0 2px #afb8c1; }
642.obsolete .mark::after {
643 content: ""; position: absolute; left: 3px; top: 7px; width: 10px; height: 2px; background: #afb8c1; transform: rotate(-45deg);
644}
640.passed .mark::after {
645.passed .mark::after {
641 content: ""; position: absolute; left: 5px; top: 2px; width: 4px; height: 8px;
646 content: ""; position: absolute; left: 5px; top: 2px; width: 4px; height: 8px;
642 border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
647 border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
internal/server/templates/layout.html +1 −1
@@ -26,7 +26,7 @@
26 26 <link rel="icon" href="/assets/logo.svg" type="image/svg+xml">
27 27 <link rel="stylesheet" href="/assets/style.css">
28 28 </head>
29 <body data-copied="{{t "action.copied"}}" data-modal-title="{{t "modal.title"}}" data-modal-ok="{{t "modal.ok"}}" data-modal-cancel="{{t "modal.cancel"}}">
29 <body data-copied="{{t "action.copied"}}" data-modal-title="{{t "modal.title"}}" data-modal-ok="{{t "modal.ok"}}" data-modal-cancel="{{t "modal.cancel"}}" data-obsolete-tip="{{t "pipe.obsolete.tip"}}">
30 30 <header class="top">
31 31 <a class="brand" href="/"><img src="/assets/logo.svg" alt=""> BlueGit</a>
32 32 <nav>
@@ -26,7 +26,7 @@
26 <link rel="icon" href="/assets/logo.svg" type="image/svg+xml">
26 <link rel="icon" href="/assets/logo.svg" type="image/svg+xml">
27 <link rel="stylesheet" href="/assets/style.css">
27 <link rel="stylesheet" href="/assets/style.css">
28</head>
28</head>
29<body data-copied="{{t "action.copied"}}" data-modal-title="{{t "modal.title"}}" data-modal-ok="{{t "modal.ok"}}" data-modal-cancel="{{t "modal.cancel"}}">
29<body data-copied="{{t "action.copied"}}" data-modal-title="{{t "modal.title"}}" data-modal-ok="{{t "modal.ok"}}" data-modal-cancel="{{t "modal.cancel"}}" data-obsolete-tip="{{t "pipe.obsolete.tip"}}">
30<header class="top">
30<header class="top">
31 <a class="brand" href="/"><img src="/assets/logo.svg" alt=""> BlueGit</a>
31 <a class="brand" href="/"><img src="/assets/logo.svg" alt=""> BlueGit</a>
32 <nav>
32 <nav>
internal/store/flow.go +71 −14
@@ -439,11 +439,15 @@ type Job struct {
439 439 Environment string
440 440 EnvironmentURL string
441 441 Interruptible bool
442 Log string
443 CommitSHA string
444 Ref string
445 StartedAt time.Time
446 FinishedAt time.Time
442 // Reason zegt waarom een job failed of canceled is: job_execution_timeout,
443 // script_failure, runner_system_failure, canceled_by_user,
444 // canceled_by_newer_pipeline. Leeg bij succes of onbekend (oude jobs).
445 Reason string
446 Log string
447 CommitSHA string
448 Ref string
449 StartedAt time.Time
450 FinishedAt time.Time
447 451 }
448 452
449 453 // RecordConfigFailure bewaart een pipeline die niet kon starten.
@@ -921,7 +925,7 @@ func (s *Store) JobsByPipeline(ctx context.Context, pipelineID int64) ([]Job, er
921 925 return out, rows.Err()
922 926 }
923 927
924 const jobSelect = `SELECT j.id, j.pipeline_id, j.repo_id, j.name, j.stage, j.position, j.status, j.image, j.script, j.needs_json, j.needs_set, j.variables_json, j.artifact_paths, j.artifact_expire_seconds, j.allow_failure, j.log, p.commit_sha, p.ref, j.before_script, j.after_script, j.when_mode, j.timeout_seconds, j.tags_json, j.cache_paths, j.cache_key, j.resource_group, j.optional_json, j.started_at, j.finished_at, j.retry_max, j.retry_when, j.attempt, j.services_json, j.environment_name, j.environment_url, j.interruptible
928 const jobSelect = `SELECT j.id, j.pipeline_id, j.repo_id, j.name, j.stage, j.position, j.status, j.image, j.script, j.needs_json, j.needs_set, j.variables_json, j.artifact_paths, j.artifact_expire_seconds, j.allow_failure, j.log, p.commit_sha, p.ref, j.before_script, j.after_script, j.when_mode, j.timeout_seconds, j.tags_json, j.cache_paths, j.cache_key, j.resource_group, j.optional_json, j.started_at, j.finished_at, j.retry_max, j.retry_when, j.attempt, j.services_json, j.environment_name, j.environment_url, j.interruptible, j.failure_reason
925 929 FROM jobs j JOIN pipelines p ON p.id = j.pipeline_id`
926 930
927 931 func scanJob(rows *sql.Rows) (Job, error) {
@@ -929,7 +933,7 @@ func scanJob(rows *sql.Rows) (Job, error) {
929 933 var needs, vars, paths, tags, cache, optional, retryWhen, services string
930 934 var needsSet, allow, expire, timeout, interruptible int
931 935 var started, finished sql.NullString
932 if err := rows.Scan(&j.ID, &j.PipelineID, &j.RepoID, &j.Name, &j.Stage, &j.Position, &j.Status, &j.Image, &j.Script, &needs, &needsSet, &vars, &paths, &expire, &allow, &j.Log, &j.CommitSHA, &j.Ref, &j.Before, &j.After, &j.When, &timeout, &tags, &cache, &j.CacheKey, &j.ResourceGroup, &optional, &started, &finished, &j.RetryMax, &retryWhen, &j.Attempt, &services, &j.Environment, &j.EnvironmentURL, &interruptible); err != nil {
936 if err := rows.Scan(&j.ID, &j.PipelineID, &j.RepoID, &j.Name, &j.Stage, &j.Position, &j.Status, &j.Image, &j.Script, &needs, &needsSet, &vars, &paths, &expire, &allow, &j.Log, &j.CommitSHA, &j.Ref, &j.Before, &j.After, &j.When, &timeout, &tags, &cache, &j.CacheKey, &j.ResourceGroup, &optional, &started, &finished, &j.RetryMax, &retryWhen, &j.Attempt, &services, &j.Environment, &j.EnvironmentURL, &interruptible, &j.Reason); err != nil {
933 937 return Job{}, err
934 938 }
935 939 j.NeedsSet = needsSet == 1
@@ -970,7 +974,7 @@ func (s *Store) ActivePipelines(ctx context.Context) ([]Pipeline, error) {
970 974
971 975 // MarkJobRunning zet een wachtende job op running als hij dat nog is.
972 976 func (s *Store) MarkJobRunning(ctx context.Context, id int64) (bool, error) {
973 res, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'running', started_at = ? WHERE id = ? AND status = 'queued'`, now(), id)
977 res, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'running', failure_reason = '', started_at = ? WHERE id = ? AND status = 'queued'`, now(), id)
974 978 if err != nil {
975 979 return false, err
976 980 }
@@ -1011,7 +1015,7 @@ func (s *Store) FailAbandonedJobs(ctx context.Context) (int, error) {
1011 1015 seen := map[int64]struct{}{}
1012 1016 var pipes []int64
1013 1017 for _, it := range found {
1014 res, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'failed', log = log || ?, finished_at = ? WHERE id = ? AND status = 'running'`, AbandonedJobNote, now(), it.id)
1018 res, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'failed', failure_reason = 'runner_system_failure', log = log || ?, finished_at = ? WHERE id = ? AND status = 'running'`, AbandonedJobNote, now(), it.id)
1015 1019 if err != nil {
1016 1020 return n, err
1017 1021 }
@@ -1044,7 +1048,13 @@ func (s *Store) CountRunningJobs(ctx context.Context) (int, error) {
1044 1048
1045 1049 // FinishJob schrijft het eindresultaat en het log.
1046 1050 func (s *Store) FinishJob(ctx context.Context, id int64, status, extra string) error {
1047 _, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = ?, log = log || ?, finished_at = ? WHERE id = ?`, status, extra, now(), id)
1051 return s.FinishJobReason(ctx, id, status, extra, "")
1052 }
1053
1054 // FinishJobReason is FinishJob met een reden (zie Job.Reason). Een lege reden
1055 // laat een eerder gezette reden staan (bijv. canceled_by_user).
1056 func (s *Store) FinishJobReason(ctx context.Context, id int64, status, extra, reason string) error {
1057 _, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = ?, log = log || ?, finished_at = ?, failure_reason = CASE WHEN ? = '' THEN failure_reason ELSE ? END WHERE id = ?`, status, extra, now(), reason, reason, id)
1048 1058 return err
1049 1059 }
1050 1060
@@ -1056,7 +1066,7 @@ func (s *Store) AppendJobLog(ctx context.Context, id int64, chunk string) error
1056 1066
1057 1067 // RequeueJob zet een mislukte job terug in de wachtrij voor een nieuwe poging.
1058 1068 func (s *Store) RequeueJob(ctx context.Context, id int64, attempt int, note string) error {
1059 _, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'queued', attempt = ?, log = log || ?, finished_at = NULL, started_at = NULL WHERE id = ?`, attempt, note, id)
1069 _, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'queued', failure_reason = '', attempt = ?, log = log || ?, finished_at = NULL, started_at = NULL WHERE id = ?`, attempt, note, id)
1060 1070 return err
1061 1071 }
1062 1072
@@ -1096,7 +1106,7 @@ func (s *Store) CancelInterruptible(ctx context.Context, repoID int64, ref strin
1096 1106 running = append(running, item.id)
1097 1107 continue
1098 1108 }
1099 if _, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'canceled', log = log || ?, finished_at = ? WHERE id = ? AND status IN ('queued', 'manual')`, note, now(), item.id); err != nil {
1109 if _, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'canceled', failure_reason = 'canceled_by_newer_pipeline', log = log || ?, finished_at = ? WHERE id = ? AND status IN ('queued', 'manual')`, note, now(), item.id); err != nil {
1100 1110 return running, pipes, err
1101 1111 }
1102 1112 }
@@ -1161,7 +1171,7 @@ func (s *Store) ResourceBusy(ctx context.Context, repoID int64, group string, ex
1161 1171
1162 1172 // RetryJob zet een mislukte of geannuleerde job terug in de wachtrij.
1163 1173 func (s *Store) RetryJob(ctx context.Context, id int64) (bool, error) {
1164 res, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'queued', finished_at = NULL WHERE id = ? AND status IN ('failed', 'canceled')`, id)
1174 res, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'queued', failure_reason = '', finished_at = NULL WHERE id = ? AND status IN ('failed', 'canceled')`, id)
1165 1175 if err != nil {
1166 1176 return false, err
1167 1177 }
@@ -1174,7 +1184,7 @@ func (s *Store) RetryJob(ctx context.Context, id int64) (bool, error) {
1174 1184
1175 1185 // CancelJob stopt een job die nog niet klaar is.
1176 1186 func (s *Store) CancelJob(ctx context.Context, id int64) (bool, error) {
1177 res, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'canceled', finished_at = ? WHERE id = ? AND status IN ('created', 'pending', 'queued', 'manual', 'running')`, now(), id)
1187 res, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'canceled', failure_reason = 'canceled_by_user', finished_at = ? WHERE id = ? AND status IN ('created', 'pending', 'queued', 'manual', 'running')`, now(), id)
1178 1188 if err != nil {
1179 1189 return false, err
1180 1190 }
@@ -1489,3 +1499,50 @@ func (s *Store) DeleteRelease(ctx context.Context, releaseID int64) ([]string, e
1489 1499 }
1490 1500 return paths, nil
1491 1501 }
1502
1503 // Redenen in Job.Reason.
1504 const (
1505 ReasonSuperseded = "canceled_by_newer_pipeline"
1506 ReasonManual = "canceled_by_user"
1507 )
1508
1509 // Obsolete is true voor een job die geannuleerd is omdat een nieuwere
1510 // pipeline op dezelfde ref startte.
1511 func (j Job) Obsolete() bool { return j.Status == "canceled" && j.Reason == ReasonSuperseded }
1512
1513 // CancelReason geeft "superseded" of "manual" voor een geannuleerde job,
1514 // anders "".
1515 func (j Job) CancelReason() string {
1516 if j.Status != "canceled" {
1517 return ""
1518 }
1519 if j.Reason == ReasonSuperseded {
1520 return "superseded"
1521 }
1522 return "manual"
1523 }
1524
1525 // FailureReason geeft de reden van een mislukte job (bijv.
1526 // job_execution_timeout), anders "".
1527 func (j Job) FailureReason() string {
1528 if j.Status != "failed" {
1529 return ""
1530 }
1531 return j.Reason
1532 }
1533
1534 // PipelineObsolete is true als elke geannuleerde job die telt (geen
1535 // allow_failure) obsolete is, en er minstens één is.
1536 func PipelineObsolete(jobs []Job) bool {
1537 seen := false
1538 for _, j := range jobs {
1539 if j.Status != "canceled" || j.AllowFailure {
1540 continue
1541 }
1542 if !j.Obsolete() {
1543 return false
1544 }
1545 seen = true
1546 }
1547 return seen
1548 }
@@ -439,11 +439,15 @@ type Job struct {
439 Environment string
439 Environment string
440 EnvironmentURL string
440 EnvironmentURL string
441 Interruptible bool
441 Interruptible bool
442 Log string
442 // Reason zegt waarom een job failed of canceled is: job_execution_timeout,
443 CommitSHA string
443 // script_failure, runner_system_failure, canceled_by_user,
444 Ref string
444 // canceled_by_newer_pipeline. Leeg bij succes of onbekend (oude jobs).
445 StartedAt time.Time
445 Reason string
446 FinishedAt time.Time
446 Log string
447 CommitSHA string
448 Ref string
449 StartedAt time.Time
450 FinishedAt time.Time
447}
451}
448
452
449// RecordConfigFailure bewaart een pipeline die niet kon starten.
453// RecordConfigFailure bewaart een pipeline die niet kon starten.
@@ -921,7 +925,7 @@ func (s *Store) JobsByPipeline(ctx context.Context, pipelineID int64) ([]Job, er
921 return out, rows.Err()
925 return out, rows.Err()
922}
926}
923
927
924const jobSelect = `SELECT j.id, j.pipeline_id, j.repo_id, j.name, j.stage, j.position, j.status, j.image, j.script, j.needs_json, j.needs_set, j.variables_json, j.artifact_paths, j.artifact_expire_seconds, j.allow_failure, j.log, p.commit_sha, p.ref, j.before_script, j.after_script, j.when_mode, j.timeout_seconds, j.tags_json, j.cache_paths, j.cache_key, j.resource_group, j.optional_json, j.started_at, j.finished_at, j.retry_max, j.retry_when, j.attempt, j.services_json, j.environment_name, j.environment_url, j.interruptible
928const jobSelect = `SELECT j.id, j.pipeline_id, j.repo_id, j.name, j.stage, j.position, j.status, j.image, j.script, j.needs_json, j.needs_set, j.variables_json, j.artifact_paths, j.artifact_expire_seconds, j.allow_failure, j.log, p.commit_sha, p.ref, j.before_script, j.after_script, j.when_mode, j.timeout_seconds, j.tags_json, j.cache_paths, j.cache_key, j.resource_group, j.optional_json, j.started_at, j.finished_at, j.retry_max, j.retry_when, j.attempt, j.services_json, j.environment_name, j.environment_url, j.interruptible, j.failure_reason
925FROM jobs j JOIN pipelines p ON p.id = j.pipeline_id`
929FROM jobs j JOIN pipelines p ON p.id = j.pipeline_id`
926
930
927func scanJob(rows *sql.Rows) (Job, error) {
931func scanJob(rows *sql.Rows) (Job, error) {
@@ -929,7 +933,7 @@ func scanJob(rows *sql.Rows) (Job, error) {
929 var needs, vars, paths, tags, cache, optional, retryWhen, services string
933 var needs, vars, paths, tags, cache, optional, retryWhen, services string
930 var needsSet, allow, expire, timeout, interruptible int
934 var needsSet, allow, expire, timeout, interruptible int
931 var started, finished sql.NullString
935 var started, finished sql.NullString
932 if err := rows.Scan(&j.ID, &j.PipelineID, &j.RepoID, &j.Name, &j.Stage, &j.Position, &j.Status, &j.Image, &j.Script, &needs, &needsSet, &vars, &paths, &expire, &allow, &j.Log, &j.CommitSHA, &j.Ref, &j.Before, &j.After, &j.When, &timeout, &tags, &cache, &j.CacheKey, &j.ResourceGroup, &optional, &started, &finished, &j.RetryMax, &retryWhen, &j.Attempt, &services, &j.Environment, &j.EnvironmentURL, &interruptible); err != nil {
936 if err := rows.Scan(&j.ID, &j.PipelineID, &j.RepoID, &j.Name, &j.Stage, &j.Position, &j.Status, &j.Image, &j.Script, &needs, &needsSet, &vars, &paths, &expire, &allow, &j.Log, &j.CommitSHA, &j.Ref, &j.Before, &j.After, &j.When, &timeout, &tags, &cache, &j.CacheKey, &j.ResourceGroup, &optional, &started, &finished, &j.RetryMax, &retryWhen, &j.Attempt, &services, &j.Environment, &j.EnvironmentURL, &interruptible, &j.Reason); err != nil {
933 return Job{}, err
937 return Job{}, err
934 }
938 }
935 j.NeedsSet = needsSet == 1
939 j.NeedsSet = needsSet == 1
@@ -970,7 +974,7 @@ func (s *Store) ActivePipelines(ctx context.Context) ([]Pipeline, error) {
970
974
971// MarkJobRunning zet een wachtende job op running als hij dat nog is.
975// MarkJobRunning zet een wachtende job op running als hij dat nog is.
972func (s *Store) MarkJobRunning(ctx context.Context, id int64) (bool, error) {
976func (s *Store) MarkJobRunning(ctx context.Context, id int64) (bool, error) {
973 res, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'running', started_at = ? WHERE id = ? AND status = 'queued'`, now(), id)
977 res, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'running', failure_reason = '', started_at = ? WHERE id = ? AND status = 'queued'`, now(), id)
974 if err != nil {
978 if err != nil {
975 return false, err
979 return false, err
976 }
980 }
@@ -1011,7 +1015,7 @@ func (s *Store) FailAbandonedJobs(ctx context.Context) (int, error) {
1011 seen := map[int64]struct{}{}
1015 seen := map[int64]struct{}{}
1012 var pipes []int64
1016 var pipes []int64
1013 for _, it := range found {
1017 for _, it := range found {
1014 res, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'failed', log = log || ?, finished_at = ? WHERE id = ? AND status = 'running'`, AbandonedJobNote, now(), it.id)
1018 res, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'failed', failure_reason = 'runner_system_failure', log = log || ?, finished_at = ? WHERE id = ? AND status = 'running'`, AbandonedJobNote, now(), it.id)
1015 if err != nil {
1019 if err != nil {
1016 return n, err
1020 return n, err
1017 }
1021 }
@@ -1044,7 +1048,13 @@ func (s *Store) CountRunningJobs(ctx context.Context) (int, error) {
1044
1048
1045// FinishJob schrijft het eindresultaat en het log.
1049// FinishJob schrijft het eindresultaat en het log.
1046func (s *Store) FinishJob(ctx context.Context, id int64, status, extra string) error {
1050func (s *Store) FinishJob(ctx context.Context, id int64, status, extra string) error {
1047 _, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = ?, log = log || ?, finished_at = ? WHERE id = ?`, status, extra, now(), id)
1051 return s.FinishJobReason(ctx, id, status, extra, "")
1052}
1053
1054// FinishJobReason is FinishJob met een reden (zie Job.Reason). Een lege reden
1055// laat een eerder gezette reden staan (bijv. canceled_by_user).
1056func (s *Store) FinishJobReason(ctx context.Context, id int64, status, extra, reason string) error {
1057 _, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = ?, log = log || ?, finished_at = ?, failure_reason = CASE WHEN ? = '' THEN failure_reason ELSE ? END WHERE id = ?`, status, extra, now(), reason, reason, id)
1048 return err
1058 return err
1049}
1059}
1050
1060
@@ -1056,7 +1066,7 @@ func (s *Store) AppendJobLog(ctx context.Context, id int64, chunk string) error
1056
1066
1057// RequeueJob zet een mislukte job terug in de wachtrij voor een nieuwe poging.
1067// RequeueJob zet een mislukte job terug in de wachtrij voor een nieuwe poging.
1058func (s *Store) RequeueJob(ctx context.Context, id int64, attempt int, note string) error {
1068func (s *Store) RequeueJob(ctx context.Context, id int64, attempt int, note string) error {
1059 _, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'queued', attempt = ?, log = log || ?, finished_at = NULL, started_at = NULL WHERE id = ?`, attempt, note, id)
1069 _, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'queued', failure_reason = '', attempt = ?, log = log || ?, finished_at = NULL, started_at = NULL WHERE id = ?`, attempt, note, id)
1060 return err
1070 return err
1061}
1071}
1062
1072
@@ -1096,7 +1106,7 @@ func (s *Store) CancelInterruptible(ctx context.Context, repoID int64, ref strin
1096 running = append(running, item.id)
1106 running = append(running, item.id)
1097 continue
1107 continue
1098 }
1108 }
1099 if _, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'canceled', log = log || ?, finished_at = ? WHERE id = ? AND status IN ('queued', 'manual')`, note, now(), item.id); err != nil {
1109 if _, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'canceled', failure_reason = 'canceled_by_newer_pipeline', log = log || ?, finished_at = ? WHERE id = ? AND status IN ('queued', 'manual')`, note, now(), item.id); err != nil {
1100 return running, pipes, err
1110 return running, pipes, err
1101 }
1111 }
1102 }
1112 }
@@ -1161,7 +1171,7 @@ func (s *Store) ResourceBusy(ctx context.Context, repoID int64, group string, ex
1161
1171
1162// RetryJob zet een mislukte of geannuleerde job terug in de wachtrij.
1172// RetryJob zet een mislukte of geannuleerde job terug in de wachtrij.
1163func (s *Store) RetryJob(ctx context.Context, id int64) (bool, error) {
1173func (s *Store) RetryJob(ctx context.Context, id int64) (bool, error) {
1164 res, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'queued', finished_at = NULL WHERE id = ? AND status IN ('failed', 'canceled')`, id)
1174 res, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'queued', failure_reason = '', finished_at = NULL WHERE id = ? AND status IN ('failed', 'canceled')`, id)
1165 if err != nil {
1175 if err != nil {
1166 return false, err
1176 return false, err
1167 }
1177 }
@@ -1174,7 +1184,7 @@ func (s *Store) RetryJob(ctx context.Context, id int64) (bool, error) {
1174
1184
1175// CancelJob stopt een job die nog niet klaar is.
1185// CancelJob stopt een job die nog niet klaar is.
1176func (s *Store) CancelJob(ctx context.Context, id int64) (bool, error) {
1186func (s *Store) CancelJob(ctx context.Context, id int64) (bool, error) {
1177 res, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'canceled', finished_at = ? WHERE id = ? AND status IN ('created', 'pending', 'queued', 'manual', 'running')`, now(), id)
1187 res, err := s.db.ExecContext(ctx, `UPDATE jobs SET status = 'canceled', failure_reason = 'canceled_by_user', finished_at = ? WHERE id = ? AND status IN ('created', 'pending', 'queued', 'manual', 'running')`, now(), id)
1178 if err != nil {
1188 if err != nil {
1179 return false, err
1189 return false, err
1180 }
1190 }
@@ -1489,3 +1499,50 @@ func (s *Store) DeleteRelease(ctx context.Context, releaseID int64) ([]string, e
1489 }
1499 }
1490 return paths, nil
1500 return paths, nil
1491}
1501}
1502
1503// Redenen in Job.Reason.
1504const (
1505 ReasonSuperseded = "canceled_by_newer_pipeline"
1506 ReasonManual = "canceled_by_user"
1507)
1508
1509// Obsolete is true voor een job die geannuleerd is omdat een nieuwere
1510// pipeline op dezelfde ref startte.
1511func (j Job) Obsolete() bool { return j.Status == "canceled" && j.Reason == ReasonSuperseded }
1512
1513// CancelReason geeft "superseded" of "manual" voor een geannuleerde job,
1514// anders "".
1515func (j Job) CancelReason() string {
1516 if j.Status != "canceled" {
1517 return ""
1518 }
1519 if j.Reason == ReasonSuperseded {
1520 return "superseded"
1521 }
1522 return "manual"
1523}
1524
1525// FailureReason geeft de reden van een mislukte job (bijv.
1526// job_execution_timeout), anders "".
1527func (j Job) FailureReason() string {
1528 if j.Status != "failed" {
1529 return ""
1530 }
1531 return j.Reason
1532}
1533
1534// PipelineObsolete is true als elke geannuleerde job die telt (geen
1535// allow_failure) obsolete is, en er minstens één is.
1536func PipelineObsolete(jobs []Job) bool {
1537 seen := false
1538 for _, j := range jobs {
1539 if j.Status != "canceled" || j.AllowFailure {
1540 continue
1541 }
1542 if !j.Obsolete() {
1543 return false
1544 }
1545 seen = true
1546 }
1547 return seen
1548}
internal/store/job_reason_test.go added +69 −0
@@ -0,0 +1,69 @@
1 package store
2
3 import (
4 "context"
5 "testing"
6 )
7
8 func TestJobReasons(t *testing.T) {
9 s := openTest(t)
10 ctx := context.Background()
11 tim, _ := s.UpsertUser(ctx, 1, "tim", "", false)
12 repo, err := s.CreateRepo(ctx, "user", tim.ID, "ci", "", "master", "private")
13 if err != nil {
14 t.Fatal(err)
15 }
16 old, err := s.CreatePipeline(ctx, repo.ID, "abc", "refs/heads/master", "push", "tim", "x", []NewJob{
17 {Name: "a", Stage: "test", Script: "true", Interruptible: true},
18 {Name: "b", Stage: "test", Script: "true"},
19 })
20 if err != nil {
21 t.Fatal(err)
22 }
23 newer, _ := s.CreatePipeline(ctx, repo.ID, "def", "refs/heads/master", "push", "tim", "y", []NewJob{{Name: "a", Stage: "test", Script: "true"}})
24 if _, _, err := s.CancelInterruptible(ctx, repo.ID, "refs/heads/master", newer); err != nil {
25 t.Fatal(err)
26 }
27 jobs, _ := s.JobsByPipeline(ctx, old)
28 for _, j := range jobs {
29 if j.Name == "a" && (!j.Obsolete() || j.CancelReason() != "superseded") {
30 t.Fatalf("a: %+v", j.Reason)
31 }
32 if j.Name == "b" {
33 if ok, _ := s.CancelJob(ctx, j.ID); !ok {
34 t.Fatal("cancel b")
35 }
36 }
37 }
38 jobs, _ = s.JobsByPipeline(ctx, old)
39 if PipelineObsolete(jobs) {
40 t.Fatal("handmatig geannuleerde job: pipeline is niet obsolete")
41 }
42 for _, j := range jobs {
43 if j.Name == "b" && (j.Obsolete() || j.CancelReason() != "manual") {
44 t.Fatalf("b: %q", j.Reason)
45 }
46 }
47 if !PipelineObsolete([]Job{{Status: "canceled", Reason: ReasonSuperseded}, {Status: "success"}, {Status: "canceled", AllowFailure: true}}) {
48 t.Fatal("alle tellende geannuleerde jobs superseded")
49 }
50 if PipelineObsolete([]Job{{Status: "success"}}) {
51 t.Fatal("geen geannuleerde job")
52 }
53 // Timeout-reden en reset bij opnieuw starten.
54 nj, _ := s.JobsByPipeline(ctx, newer)
55 if err := s.FinishJobReason(ctx, nj[0].ID, "failed", "Job timed out after 1m\n", "job_execution_timeout"); err != nil {
56 t.Fatal(err)
57 }
58 nj, _ = s.JobsByPipeline(ctx, newer)
59 if nj[0].FailureReason() != "job_execution_timeout" || nj[0].CancelReason() != "" {
60 t.Fatalf("timeout: %q", nj[0].Reason)
61 }
62 if err := s.RequeueJob(ctx, nj[0].ID, 1, ""); err != nil {
63 t.Fatal(err)
64 }
65 nj, _ = s.JobsByPipeline(ctx, newer)
66 if nj[0].Reason != "" {
67 t.Fatal("reden blijft staan na requeue")
68 }
69 }
@@ -0,0 +1,69 @@
1package store
2
3import (
4 "context"
5 "testing"
6)
7
8func TestJobReasons(t *testing.T) {
9 s := openTest(t)
10 ctx := context.Background()
11 tim, _ := s.UpsertUser(ctx, 1, "tim", "", false)
12 repo, err := s.CreateRepo(ctx, "user", tim.ID, "ci", "", "master", "private")
13 if err != nil {
14 t.Fatal(err)
15 }
16 old, err := s.CreatePipeline(ctx, repo.ID, "abc", "refs/heads/master", "push", "tim", "x", []NewJob{
17 {Name: "a", Stage: "test", Script: "true", Interruptible: true},
18 {Name: "b", Stage: "test", Script: "true"},
19 })
20 if err != nil {
21 t.Fatal(err)
22 }
23 newer, _ := s.CreatePipeline(ctx, repo.ID, "def", "refs/heads/master", "push", "tim", "y", []NewJob{{Name: "a", Stage: "test", Script: "true"}})
24 if _, _, err := s.CancelInterruptible(ctx, repo.ID, "refs/heads/master", newer); err != nil {
25 t.Fatal(err)
26 }
27 jobs, _ := s.JobsByPipeline(ctx, old)
28 for _, j := range jobs {
29 if j.Name == "a" && (!j.Obsolete() || j.CancelReason() != "superseded") {
30 t.Fatalf("a: %+v", j.Reason)
31 }
32 if j.Name == "b" {
33 if ok, _ := s.CancelJob(ctx, j.ID); !ok {
34 t.Fatal("cancel b")
35 }
36 }
37 }
38 jobs, _ = s.JobsByPipeline(ctx, old)
39 if PipelineObsolete(jobs) {
40 t.Fatal("handmatig geannuleerde job: pipeline is niet obsolete")
41 }
42 for _, j := range jobs {
43 if j.Name == "b" && (j.Obsolete() || j.CancelReason() != "manual") {
44 t.Fatalf("b: %q", j.Reason)
45 }
46 }
47 if !PipelineObsolete([]Job{{Status: "canceled", Reason: ReasonSuperseded}, {Status: "success"}, {Status: "canceled", AllowFailure: true}}) {
48 t.Fatal("alle tellende geannuleerde jobs superseded")
49 }
50 if PipelineObsolete([]Job{{Status: "success"}}) {
51 t.Fatal("geen geannuleerde job")
52 }
53 // Timeout-reden en reset bij opnieuw starten.
54 nj, _ := s.JobsByPipeline(ctx, newer)
55 if err := s.FinishJobReason(ctx, nj[0].ID, "failed", "Job timed out after 1m\n", "job_execution_timeout"); err != nil {
56 t.Fatal(err)
57 }
58 nj, _ = s.JobsByPipeline(ctx, newer)
59 if nj[0].FailureReason() != "job_execution_timeout" || nj[0].CancelReason() != "" {
60 t.Fatalf("timeout: %q", nj[0].Reason)
61 }
62 if err := s.RequeueJob(ctx, nj[0].ID, 1, ""); err != nil {
63 t.Fatal(err)
64 }
65 nj, _ = s.JobsByPipeline(ctx, newer)
66 if nj[0].Reason != "" {
67 t.Fatal("reden blijft staan na requeue")
68 }
69}
internal/store/store.go +6 −0
@@ -77,6 +77,11 @@ func (s *Store) migrate() error {
77 77 `ALTER TABLE jobs ADD COLUMN after_script TEXT NOT NULL DEFAULT ''`,
78 78 `ALTER TABLE jobs ADD COLUMN when_mode TEXT NOT NULL DEFAULT 'on_success'`,
79 79 `ALTER TABLE jobs ADD COLUMN timeout_seconds INTEGER NOT NULL DEFAULT 0`,
80 `ALTER TABLE jobs ADD COLUMN failure_reason TEXT NOT NULL DEFAULT ''`,
81 // Oude geannuleerde jobs: alleen een onderbreekbare job met de melding
82 // in het log is echt door een nieuwere pipeline gestopt. Vóór deze
83 // versie schreef de runner die melding ook bij handmatig annuleren.
84 `UPDATE jobs SET failure_reason = CASE WHEN interruptible = 1 AND log LIKE '%canceled because a newer pipeline started for the same ref%' THEN 'canceled_by_newer_pipeline' ELSE 'canceled_by_user' END WHERE status = 'canceled' AND failure_reason = ''`,
80 85 `ALTER TABLE jobs ADD COLUMN tags_json TEXT NOT NULL DEFAULT '[]'`,
81 86 `ALTER TABLE jobs ADD COLUMN cache_paths TEXT NOT NULL DEFAULT '[]'`,
82 87 `ALTER TABLE jobs ADD COLUMN cache_key TEXT NOT NULL DEFAULT ''`,
@@ -338,6 +343,7 @@ CREATE TABLE IF NOT EXISTS jobs (
338 343 after_script TEXT NOT NULL DEFAULT '',
339 344 when_mode TEXT NOT NULL DEFAULT 'on_success',
340 345 timeout_seconds INTEGER NOT NULL DEFAULT 0,
346 failure_reason TEXT NOT NULL DEFAULT '',
341 347 tags_json TEXT NOT NULL DEFAULT '[]',
342 348 cache_paths TEXT NOT NULL DEFAULT '[]',
343 349 cache_key TEXT NOT NULL DEFAULT '',
@@ -77,6 +77,11 @@ func (s *Store) migrate() error {
77 `ALTER TABLE jobs ADD COLUMN after_script TEXT NOT NULL DEFAULT ''`,
77 `ALTER TABLE jobs ADD COLUMN after_script TEXT NOT NULL DEFAULT ''`,
78 `ALTER TABLE jobs ADD COLUMN when_mode TEXT NOT NULL DEFAULT 'on_success'`,
78 `ALTER TABLE jobs ADD COLUMN when_mode TEXT NOT NULL DEFAULT 'on_success'`,
79 `ALTER TABLE jobs ADD COLUMN timeout_seconds INTEGER NOT NULL DEFAULT 0`,
79 `ALTER TABLE jobs ADD COLUMN timeout_seconds INTEGER NOT NULL DEFAULT 0`,
80 `ALTER TABLE jobs ADD COLUMN failure_reason TEXT NOT NULL DEFAULT ''`,
81 // Oude geannuleerde jobs: alleen een onderbreekbare job met de melding
82 // in het log is echt door een nieuwere pipeline gestopt. Vóór deze
83 // versie schreef de runner die melding ook bij handmatig annuleren.
84 `UPDATE jobs SET failure_reason = CASE WHEN interruptible = 1 AND log LIKE '%canceled because a newer pipeline started for the same ref%' THEN 'canceled_by_newer_pipeline' ELSE 'canceled_by_user' END WHERE status = 'canceled' AND failure_reason = ''`,
80 `ALTER TABLE jobs ADD COLUMN tags_json TEXT NOT NULL DEFAULT '[]'`,
85 `ALTER TABLE jobs ADD COLUMN tags_json TEXT NOT NULL DEFAULT '[]'`,
81 `ALTER TABLE jobs ADD COLUMN cache_paths TEXT NOT NULL DEFAULT '[]'`,
86 `ALTER TABLE jobs ADD COLUMN cache_paths TEXT NOT NULL DEFAULT '[]'`,
82 `ALTER TABLE jobs ADD COLUMN cache_key TEXT NOT NULL DEFAULT ''`,
87 `ALTER TABLE jobs ADD COLUMN cache_key TEXT NOT NULL DEFAULT ''`,
@@ -338,6 +343,7 @@ CREATE TABLE IF NOT EXISTS jobs (
338 after_script TEXT NOT NULL DEFAULT '',
343 after_script TEXT NOT NULL DEFAULT '',
339 when_mode TEXT NOT NULL DEFAULT 'on_success',
344 when_mode TEXT NOT NULL DEFAULT 'on_success',
340 timeout_seconds INTEGER NOT NULL DEFAULT 0,
345 timeout_seconds INTEGER NOT NULL DEFAULT 0,
346 failure_reason TEXT NOT NULL DEFAULT '',
341 tags_json TEXT NOT NULL DEFAULT '[]',
347 tags_json TEXT NOT NULL DEFAULT '[]',
342 cache_paths TEXT NOT NULL DEFAULT '[]',
348 cache_paths TEXT NOT NULL DEFAULT '[]',
343 cache_key TEXT NOT NULL DEFAULT '',
349 cache_key TEXT NOT NULL DEFAULT '',
internal/webhook/openapi.go +11 −9
@@ -227,15 +227,17 @@ func OpenAPI() []byte {
227 227 "url": str("Pipeline page."),
228 228 }, []string{"id", "status", "ref", "sha", "commit_message", "author", "duration"}),
229 229 "Job": obj("One job. log is always the console tail. log_url is present only when log_truncated is true.", map[string]any{
230 "name": str("Job name."),
231 "stage": str("Stage name."),
232 "status": str("Job status."),
233 "duration": num("Seconds the job ran."),
234 "allow_failure": boolean("True when a failure does not fail the pipeline."),
235 "web_url": str("Job page."),
236 "log": str("Last 200 lines of the console output, at most 64 KiB. Secrets of at least 8 characters are [MASKED]."),
237 "log_truncated": boolean("True when log is shorter than the stored console output."),
238 "log_url": str("GET /api/v1/repos/{owner}/{repo}/jobs/{id}/log. Present only when log_truncated is true. Requires Authorization Bearer and a personal token that can read the repo. The response is the full log as text/plain, with secrets masked."),
230 "name": str("Job name."),
231 "stage": str("Stage name."),
232 "status": str("Job status."),
233 "duration": num("Seconds the job ran."),
234 "allow_failure": boolean("True when a failure does not fail the pipeline."),
235 "web_url": str("Job page."),
236 "log": str("Last 200 lines of the console output, at most 64 KiB. Secrets of at least 8 characters are [MASKED]."),
237 "log_truncated": boolean("True when log is shorter than the stored console output."),
238 "cancel_reason": str("Only for status canceled: superseded (a newer pipeline started for the same ref; shown as Obsolete) or manual."),
239 "failure_reason": str("Only for status failed, when known: job_execution_timeout, script_failure or runner_system_failure."),
240 "log_url": str("GET /api/v1/repos/{owner}/{repo}/jobs/{id}/log. Present only when log_truncated is true. Requires Authorization Bearer and a personal token that can read the repo. The response is the full log as text/plain, with secrets masked."),
239 241 }, []string{"name", "stage", "status", "duration", "allow_failure", "web_url", "log", "log_truncated"}),
240 242 "PushEvent": obj("A branch or tag update.", map[string]any{
241 243 "object_kind": str("Always push."),
@@ -227,15 +227,17 @@ func OpenAPI() []byte {
227 "url": str("Pipeline page."),
227 "url": str("Pipeline page."),
228 }, []string{"id", "status", "ref", "sha", "commit_message", "author", "duration"}),
228 }, []string{"id", "status", "ref", "sha", "commit_message", "author", "duration"}),
229 "Job": obj("One job. log is always the console tail. log_url is present only when log_truncated is true.", map[string]any{
229 "Job": obj("One job. log is always the console tail. log_url is present only when log_truncated is true.", map[string]any{
230 "name": str("Job name."),
230 "name": str("Job name."),
231 "stage": str("Stage name."),
231 "stage": str("Stage name."),
232 "status": str("Job status."),
232 "status": str("Job status."),
233 "duration": num("Seconds the job ran."),
233 "duration": num("Seconds the job ran."),
234 "allow_failure": boolean("True when a failure does not fail the pipeline."),
234 "allow_failure": boolean("True when a failure does not fail the pipeline."),
235 "web_url": str("Job page."),
235 "web_url": str("Job page."),
236 "log": str("Last 200 lines of the console output, at most 64 KiB. Secrets of at least 8 characters are [MASKED]."),
236 "log": str("Last 200 lines of the console output, at most 64 KiB. Secrets of at least 8 characters are [MASKED]."),
237 "log_truncated": boolean("True when log is shorter than the stored console output."),
237 "log_truncated": boolean("True when log is shorter than the stored console output."),
238 "log_url": str("GET /api/v1/repos/{owner}/{repo}/jobs/{id}/log. Present only when log_truncated is true. Requires Authorization Bearer and a personal token that can read the repo. The response is the full log as text/plain, with secrets masked."),
238 "cancel_reason": str("Only for status canceled: superseded (a newer pipeline started for the same ref; shown as Obsolete) or manual."),
239 "failure_reason": str("Only for status failed, when known: job_execution_timeout, script_failure or runner_system_failure."),
240 "log_url": str("GET /api/v1/repos/{owner}/{repo}/jobs/{id}/log. Present only when log_truncated is true. Requires Authorization Bearer and a personal token that can read the repo. The response is the full log as text/plain, with secrets masked."),
239 }, []string{"name", "stage", "status", "duration", "allow_failure", "web_url", "log", "log_truncated"}),
241 }, []string{"name", "stage", "status", "duration", "allow_failure", "web_url", "log", "log_truncated"}),
240 "PushEvent": obj("A branch or tag update.", map[string]any{
242 "PushEvent": obj("A branch or tag update.", map[string]any{
241 "object_kind": str("Always push."),
243 "object_kind": str("Always push."),
internal/webhook/payload.go +4 −0
@@ -82,6 +82,10 @@ type JobInfo struct {
82 82 Log string `json:"log"`
83 83 LogTruncated bool `json:"log_truncated"`
84 84 LogURL string `json:"log_url,omitempty"`
85 // CancelReason is superseded (nieuwere pipeline) of manual bij status canceled.
86 CancelReason string `json:"cancel_reason,omitempty"`
87 // FailureReason is bijv. job_execution_timeout bij status failed.
88 FailureReason string `json:"failure_reason,omitempty"`
85 89 }
86 90
87 91 // CommitInfo is één commit in een push of merge request.
@@ -82,6 +82,10 @@ type JobInfo struct {
82 Log string `json:"log"`
82 Log string `json:"log"`
83 LogTruncated bool `json:"log_truncated"`
83 LogTruncated bool `json:"log_truncated"`
84 LogURL string `json:"log_url,omitempty"`
84 LogURL string `json:"log_url,omitempty"`
85 // CancelReason is superseded (nieuwere pipeline) of manual bij status canceled.
86 CancelReason string `json:"cancel_reason,omitempty"`
87 // FailureReason is bijv. job_execution_timeout bij status failed.
88 FailureReason string `json:"failure_reason,omitempty"`
85}
89}
86
90
87// CommitInfo is één commit in een push of merge request.
91// CommitInfo is één commit in een push of merge request.
scripts/bg +3 −3
@@ -64,9 +64,9 @@ find_pipeline() {
64 64 }
65 65 show_pipeline() {
66 66 local p=$1 pipe=$2
67 jq -r '"pipeline #\(.id) \(.status) \(.ref|sub("^refs/heads/";"")) \(.sha[0:8]) \(.web_url)"' <<<"$pipe"
67 jq -r '"pipeline #\(.id) \(.display_status // .status) \(.ref|sub("^refs/heads/";"")) \(.sha[0:8]) \(.web_url)"' <<<"$pipe"
68 68 get "$(proj "$p")/pipelines/$(jq -r .id <<<"$pipe")/jobs" |
69 jq -r '.[] | " \(.id)\t\(.status)\t\(.stage)/\(.name)\(if .allow_failure then " (allow_failure)" else "" end)"'
69 jq -r '.[] | " \(.id)\t\(.display_status // .status)\(if .failure_reason then " (\(.failure_reason))" else "" end)\t\(.stage)/\(.name)\(if .allow_failure then " (allow_failure)" else "" end)"'
70 70 }
71 71 failed_logs() {
72 72 local p=$1 id=$2 jobs
@@ -110,7 +110,7 @@ cmd_pipeline() {
110 110 local mode=failed
111 111 [[ ${3:-} == --all ]] && mode=all
112 112 req POST "$(proj "${1:?project}")/pipelines/${2:?pipeline-id}/retry" "$(json --arg m "$mode" '{mode:$m}')" | jq -r '"pipeline #\(.id) \(.status) \(.web_url)"' ;;
113 list) get "$(proj "${1:?project}")/pipelines?per_page=${2:-10}" | jq -r '.[]|"\(.id)\t\(.status)\t\(.ref|sub("^refs/heads/";""))\t\(.sha[0:8])"' ;;
113 list) get "$(proj "${1:?project}")/pipelines?per_page=${2:-10}" | jq -r '.[]|"\(.id)\t\(.display_status // .status)\t\(.ref|sub("^refs/heads/";""))\t\(.sha[0:8])"' ;;
114 114 *) die "pipeline status|wait|logs|retry|list" ;;
115 115 esac
116 116 }
@@ -64,9 +64,9 @@ find_pipeline() {
64}
64}
65show_pipeline() {
65show_pipeline() {
66 local p=$1 pipe=$2
66 local p=$1 pipe=$2
67 jq -r '"pipeline #\(.id) \(.status) \(.ref|sub("^refs/heads/";"")) \(.sha[0:8]) \(.web_url)"' <<<"$pipe"
67 jq -r '"pipeline #\(.id) \(.display_status // .status) \(.ref|sub("^refs/heads/";"")) \(.sha[0:8]) \(.web_url)"' <<<"$pipe"
68 get "$(proj "$p")/pipelines/$(jq -r .id <<<"$pipe")/jobs" |
68 get "$(proj "$p")/pipelines/$(jq -r .id <<<"$pipe")/jobs" |
69 jq -r '.[] | " \(.id)\t\(.status)\t\(.stage)/\(.name)\(if .allow_failure then " (allow_failure)" else "" end)"'
69 jq -r '.[] | " \(.id)\t\(.display_status // .status)\(if .failure_reason then " (\(.failure_reason))" else "" end)\t\(.stage)/\(.name)\(if .allow_failure then " (allow_failure)" else "" end)"'
70}
70}
71failed_logs() {
71failed_logs() {
72 local p=$1 id=$2 jobs
72 local p=$1 id=$2 jobs
@@ -110,7 +110,7 @@ cmd_pipeline() {
110 local mode=failed
110 local mode=failed
111 [[ ${3:-} == --all ]] && mode=all
111 [[ ${3:-} == --all ]] && mode=all
112 req POST "$(proj "${1:?project}")/pipelines/${2:?pipeline-id}/retry" "$(json --arg m "$mode" '{mode:$m}')" | jq -r '"pipeline #\(.id) \(.status) \(.web_url)"' ;;
112 req POST "$(proj "${1:?project}")/pipelines/${2:?pipeline-id}/retry" "$(json --arg m "$mode" '{mode:$m}')" | jq -r '"pipeline #\(.id) \(.status) \(.web_url)"' ;;
113 list) get "$(proj "${1:?project}")/pipelines?per_page=${2:-10}" | jq -r '.[]|"\(.id)\t\(.status)\t\(.ref|sub("^refs/heads/";""))\t\(.sha[0:8])"' ;;
113 list) get "$(proj "${1:?project}")/pipelines?per_page=${2:-10}" | jq -r '.[]|"\(.id)\t\(.display_status // .status)\t\(.ref|sub("^refs/heads/";""))\t\(.sha[0:8])"' ;;
114 *) die "pipeline status|wait|logs|retry|list" ;;
114 *) die "pipeline status|wait|logs|retry|list" ;;
115 esac
115 esac
116}
116}