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

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
before after

How to set up and validate locally

  1. 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
  2. On the pipeline page, select Group jobs by > Job dependencies.

  3. build-job and lint-job are in the first column, test-job and deploy-job are in the second. Without this change there are three columns: build-job, then test-job and lint-job, then deploy-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.

Merge request reports

Loading
Loading