Skip to content

Commit c8fca24

Browse files
authored
fix(pkg/jenkins): treat the zero number build as enqueued state (#26)
* Revert "Fix Jenkins operator reporting invalid URLs with build number 0 (#23)" This reverts commit c4199af. * fix(pkg/jenkins): use enqueued flag for builds with zero number in `GetBuilds` method
1 parent 1f667ad commit c8fca24

3 files changed

Lines changed: 5 additions & 57 deletions

File tree

pkg/jenkins/controller.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,6 @@ func (c *Controller) syncPendingJob(pj prowapi.ProwJob, reports chan<- prowapi.P
365365
case jb.IsRunning():
366366
// Build still going.
367367
c.incrementNumPendingJobs(pj.Spec.Job)
368-
// Do not update the commit status when build number is 0.
369-
// Build number 0 indicates the Jenkins job hasn't been properly assigned a build number yet.
370-
if jb.Number == 0 {
371-
c.log.WithFields(pjutil.ProwJobFields(&pj)).Debug("Skipping status update for build with number 0")
372-
return nil
373-
}
374368
if pj.Status.Description == "Jenkins job running." && pj.Status.URL != "" {
375369
return nil
376370
}
@@ -458,12 +452,6 @@ func (c *Controller) syncTriggeredJob(pj prowapi.ProwJob, reports chan<- prowapi
458452
// Still in queue.
459453
pj.Status.Description = "Jenkins job enqueued."
460454
} else if jb.IsRunning() {
461-
// Do not update the commit status when build number is 0.
462-
// Build number 0 indicates the Jenkins job hasn't been properly assigned a build number yet.
463-
if jb.Number == 0 {
464-
c.log.WithFields(pjutil.ProwJobFields(&pj)).Debug("Skipping status update for build with number 0")
465-
return nil
466-
}
467455
// If a Jenkins build already exists for this job, advance the ProwJob to Pending and
468456
// it should be handled by syncPendingJob in the next sync.
469457
if pj.Status.PendingTime == nil {

pkg/jenkins/controller_test.go

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -295,28 +295,6 @@ func TestSyncTriggeredJobs(t *testing.T) {
295295
expectedEnqueued: true,
296296
expectedPendingTime: nil,
297297
},
298-
{
299-
name: "running job with build number 0, should not report",
300-
pj: prowapi.ProwJob{
301-
ObjectMeta: metav1.ObjectMeta{
302-
Name: "zerobuild",
303-
Namespace: "prowjobs",
304-
},
305-
Spec: prowapi.ProwJobSpec{
306-
Type: prowapi.PostsubmitJob,
307-
},
308-
Status: prowapi.ProwJobStatus{
309-
State: prowapi.TriggeredState,
310-
},
311-
},
312-
builds: map[string]Build{
313-
"zerobuild": {enqueued: false, Number: 0},
314-
},
315-
expectedBuild: false,
316-
expectedReport: false,
317-
expectedState: prowapi.TriggeredState,
318-
expectedPendingTime: nil,
319-
},
320298
}
321299
for _, tc := range testcases {
322300
totServ := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -548,26 +526,6 @@ func TestSyncPendingJobs(t *testing.T) {
548526
expectedComplete: true,
549527
expectedReport: true,
550528
},
551-
{
552-
name: "building with build number 0, should not report",
553-
pj: prowapi.ProwJob{
554-
ObjectMeta: metav1.ObjectMeta{
555-
Name: "zerobuild",
556-
Namespace: "prowjobs",
557-
},
558-
Spec: prowapi.ProwJobSpec{
559-
Job: "test-job",
560-
},
561-
Status: prowapi.ProwJobStatus{
562-
State: prowapi.PendingState,
563-
},
564-
},
565-
builds: map[string]Build{
566-
"zerobuild": {enqueued: false, Number: 0},
567-
},
568-
expectedState: prowapi.PendingState,
569-
expectedReport: false,
570-
},
571529
}
572530
for _, tc := range testcases {
573531
t.Logf("scenario %q", tc.name)

pkg/jenkins/jenkins.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"errors"
2323
"fmt"
2424
stdio "io"
25+
"maps"
2526
"net/http"
2627
"net/url"
2728
"strings"
@@ -670,9 +671,7 @@ func (c *Client) ListBuilds(jobs []BuildQueryParams) (map[string]Build, error) {
670671
}
671672

672673
for builds := range buildChan {
673-
for id, build := range builds {
674-
jenkinsBuilds[id] = build
675-
}
674+
maps.Copy(jenkinsBuilds, builds)
676675
}
677676

678677
return jenkinsBuilds, nil
@@ -744,6 +743,9 @@ func (c *Client) GetBuilds(job string) (map[string]Build, error) {
744743
if prowJobID == "" {
745744
continue
746745
}
746+
if jb.Number == 0 {
747+
jb.enqueued = true
748+
}
747749
jenkinsBuilds[prowJobID] = jb
748750
}
749751
return jenkinsBuilds, nil

0 commit comments

Comments
 (0)