Place jobs by needs in the job dependencies view
What does this MR do and why?
Since 18.5, the Job dependencies view doesn't take needs into account when it picks a column for a job. Every job goes after the whole previous stage. A job with needs: [] in the test stage ends up in the second column instead of the first, and a pipeline with many stages turns into one long row. The lint-job example in the docs no longer matches what you see.
The view used to get dependencies from previousStageJobsOrNeeds. For a job with needs, that field returned the needs. For any other job, it returned the previous stage. After the field was removed from the query, the frontend started adding the previous stage jobs to every job.
This MR fetches schedulingType together with the needs. The previous stage jobs are added only when the job doesn't use needs. The dependency lines and the stage view stay the same.
References
- Closes #599603 (closed)
- Closes #597956 (closed)
- Introduced in !204832 (merged)
- Expected behavior: https://docs.gitlab.com/ci/pipelines/#group-jobs-by-stage-or-needs-configuration
Screenshots or screen recordings
Same pipeline (config from the steps below) on 19.1, with the fix applied to the frontend locally for the "after" one.
Before: lint-job has needs: [] but sits in the second column, and deploy-job sits in the third even though it only needs build-job.
After: lint-job is in the first column, deploy-job right after build-job.
| Before | After |
|---|---|
![]() |
![]() |
How to set up and validate locally
-
Run a pipeline with this
.gitlab-ci.yml:stages: [build, test, deploy] build-job: stage: build script: echo build test-job: stage: test script: echo test lint-job: stage: test needs: [] script: echo lint deploy-job: stage: deploy needs: [build-job] script: echo deploy -
On the pipeline page, select Group jobs by > Job dependencies.
-
build-jobandlint-jobare in the first column,test-jobanddeploy-jobare in the second. Without this change there are three columns:build-job, thentest-jobandlint-job, thendeploy-job.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

