Skip to content

Commit f91148e

Browse files
authored
fix(api): manage empty jobs (#7467)
1 parent 327fa49 commit f91148e

1 file changed

Lines changed: 8 additions & 28 deletions

File tree

engine/api/v2_workflow_run_engine.go

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func (api *API) workflowRunV2Trigger(ctx context.Context, wrEnqueue sdk.V2Workfl
269269
// Enqueue JOB
270270
hasTemplatedMatrixedJob := false
271271
for _, j := range jobsToQueue {
272-
if !j.Status.IsTerminated() && j.Job.From != "" && j.Job.Strategy != nil && len(j.Job.Strategy.Matrix) > 0 {
272+
if j.Job.From != "" && j.Job.Strategy != nil && len(j.Job.Strategy.Matrix) > 0 {
273273
hasTemplatedMatrixedJob = true
274274
}
275275
}
@@ -1202,32 +1202,6 @@ func prepareRunJobs(ctx context.Context, db *gorp.DbMap, store cache.Store, proj
12021202
for jobID, jobToTrigger := range jobsToQueue {
12031203
jobDef := jobToTrigger.Job
12041204

1205-
// If no step && no template: rj is success
1206-
if (jobToTrigger.Status.IsTerminated() && jobToTrigger.Job.From != "") || (len(jobDef.Steps) == 0 && jobDef.From == "") {
1207-
runJob := sdk.V2WorkflowRunJob{
1208-
WorkflowRunID: run.ID,
1209-
Status: sdk.V2WorkflowRunJobStatusSuccess,
1210-
JobID: jobID,
1211-
Job: jobDef,
1212-
DeprecatedUserID: wrEnqueue.Initiator.UserID,
1213-
DeprecatedUsername: wrEnqueue.Initiator.Username(),
1214-
DeprecatedAdminMFA: wrEnqueue.Initiator.IsAdminWithMFA,
1215-
ProjectKey: run.ProjectKey,
1216-
VCSServer: run.VCSServer,
1217-
Repository: run.Repository,
1218-
Region: jobDef.Region,
1219-
WorkflowName: run.WorkflowName,
1220-
RunNumber: run.RunNumber,
1221-
RunAttempt: run.RunAttempt,
1222-
Initiator: wrEnqueue.Initiator,
1223-
}
1224-
if jobToTrigger.Status.IsTerminated() {
1225-
runJob.Status = jobToTrigger.Status
1226-
}
1227-
runJobs = append(runJobs, runJob)
1228-
continue
1229-
}
1230-
12311205
runJobContext := sdk.WorkflowRunJobsContext{
12321206
WorkflowRunContext: sdk.WorkflowRunContext{
12331207
CDS: run.Contexts.CDS,
@@ -1308,6 +1282,9 @@ func prepareRunJobs(ctx context.Context, db *gorp.DbMap, store cache.Store, proj
13081282
RunAttempt: run.RunAttempt,
13091283
Initiator: wrEnqueue.Initiator,
13101284
}
1285+
if len(jobDef.Steps) == 0 && !jobToTrigger.Status.IsTerminated() {
1286+
runJob.Status = sdk.V2WorkflowRunJobStatusSuccess
1287+
}
13111288
// If the current job was a matrix, skip it
13121289
if jobDef.Strategy != nil && len(jobDef.Strategy.Matrix) > 0 {
13131290
runJob.Status = sdk.V2WorkflowRunJobStatusSkipped
@@ -1596,6 +1573,9 @@ func createMatrixedRunJobs(ctx context.Context, db *gorp.DbMap, store cache.Stor
15961573
Matrix: sdk.JobMatrix{},
15971574
Initiator: data.wrEnqueue.Initiator,
15981575
}
1576+
if len(data.jobToTrigger.Job.Steps) == 0 && !data.jobToTrigger.Status.IsTerminated() {
1577+
runJob.Status = sdk.V2WorkflowRunJobStatusSuccess
1578+
}
15991579
for k, v := range m {
16001580
runJob.Matrix[k] = v
16011581
}
@@ -2013,7 +1993,7 @@ func computeRunStatusFromJobsStatus(ctx context.Context, db gorp.SqlExecutor, ru
20131993
allJobID[rj.JobID] = struct{}{}
20141994
}
20151995

2016-
if len(allJobID) < nbJob && finalStatus == sdk.V2WorkflowRunStatusSuccess {
1996+
if len(allJobID) < nbJob && finalStatus.IsTerminated() {
20171997
finalStatus = sdk.V2WorkflowRunStatusBuilding
20181998
} else if len(allJobID) == nbJob && allSkipped {
20191999
finalStatus = sdk.V2WorkflowRunStatusSkipped

0 commit comments

Comments
 (0)