From d80915de468888f123d41d489a1ff5dab3fcb761 Mon Sep 17 00:00:00 2001 From: Fabian Holler Date: Thu, 7 Sep 2023 12:58:16 +0200 Subject: [PATCH] print warning if status of a stage is in_progress Because we only return builds from the jenkins clients if their building status is false, it should not happen that a stage has an in_progress state. If it happens anyways, log a warning. --- internal/jenkins/builds.go | 11 +++++++++++ main.go | 16 ++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/internal/jenkins/builds.go b/internal/jenkins/builds.go index 9ba0da8..e44cf6f 100644 --- a/internal/jenkins/builds.go +++ b/internal/jenkins/builds.go @@ -47,6 +47,17 @@ type Build struct { Building bool } +func (b *Build) FullJobName() string { + if b.MultiBranchJobName != "" { + return b.MultiBranchJobName + "/" + b.JobName + } + return b.JobName +} + +func (b *Build) String() string { + return b.FullJobName() + " #" + fmt.Sprint(b.ID) +} + func (b *buildRawResp) validate() error { if b.Building == nil { return errors.New("Building field is missing (nil)") diff --git a/main.go b/main.go index 912bbbd..635e5e0 100644 --- a/main.go +++ b/main.go @@ -155,15 +155,9 @@ func buildsByJob(builds []*jenkins.Build) map[string][]*jenkins.Build { res := map[string][]*jenkins.Build{} for _, b := range builds { - var jobName string - - if b.MultiBranchJobName != "" { - jobName = b.MultiBranchJobName + "/" - } - jobName += b.JobName + jobName := b.FullJobName() jobBuilds := res[jobName] - res[jobName] = append(jobBuilds, b) } @@ -318,7 +312,13 @@ func recordStagesMetric(metrics *jenkinsexporter.Metrics, b *jenkins.Build, stag continue } - if *ignoreUnsuccessfulBuildStages && !strings.EqualFold(stage.Status, "success") { + if strings.EqualFold(stage.Status, "IN_PROGRESS") { + log.Printf("%s: skipping recording stage metrics for %q, stage status is %q, expected build to be finished. This should not happen, please open a bug report", + b, stage.Name, stage.Status) + continue + } + + if *ignoreUnsuccessfulBuildStages && !strings.EqualFold(stage.Status, "SUCCESS") { continue }