Skip to content

Commit

Permalink
print warning if status of a stage is in_progress
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fho committed Sep 7, 2023
1 parent c06dfad commit d80915d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
11 changes: 11 additions & 0 deletions internal/jenkins/builds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down
16 changes: 8 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit d80915d

Please sign in to comment.