Skip to content

Commit c4199af

Browse files
Copilotwuhuizuo
andauthored
Fix Jenkins operator reporting invalid URLs with build number 0 (#23)
* Initial plan * Fix Jenkins operator to skip status update when build number is 0 Co-authored-by: wuhuizuo <2574558+wuhuizuo@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: wuhuizuo <2574558+wuhuizuo@users.noreply.github.com>
1 parent a0cfed2 commit c4199af

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

pkg/jenkins/controller.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,12 @@ 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+
}
368374
if pj.Status.Description == "Jenkins job running." && pj.Status.URL != "" {
369375
return nil
370376
}
@@ -452,6 +458,12 @@ func (c *Controller) syncTriggeredJob(pj prowapi.ProwJob, reports chan<- prowapi
452458
// Still in queue.
453459
pj.Status.Description = "Jenkins job enqueued."
454460
} 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+
}
455467
// If a Jenkins build already exists for this job, advance the ProwJob to Pending and
456468
// it should be handled by syncPendingJob in the next sync.
457469
if pj.Status.PendingTime == nil {

pkg/jenkins/controller_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,28 @@ 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+
},
298320
}
299321
for _, tc := range testcases {
300322
totServ := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -526,6 +548,26 @@ func TestSyncPendingJobs(t *testing.T) {
526548
expectedComplete: true,
527549
expectedReport: true,
528550
},
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+
},
529571
}
530572
for _, tc := range testcases {
531573
t.Logf("scenario %q", tc.name)

0 commit comments

Comments
 (0)