Skip to content

Add previousStageJobs to JobType

Avielle Wolfe requested to merge 424255-previous-stages-jobs into master

What does this MR do and why?

This MR adds previousStageJobs field to Ci::JobType. This field will be used with the existing needs field to provide a more performant replace to the previousStageJobsOrNeeds field.

This MR also fixes an existing N+1 in the previous_stage_jobs method. This removes the N+1 from both the new previousStageJobs field and from previousStageJobsOrNeeds

Issues: #424255 (closed), #389195 (closed), #422079 (closed)

Screenshots or screen recordings

Screenshot_2023-09-07_at_14.05.06

The above query comes from a pipeline run using this .gitlab-ci.yml:

build:
  script: ls
  stage: build

test:
  script: ls
  stage: test

deploy:
  script: ls
  stage: deploy

How to set up and validate locally

  1. Run a pipeline using this .gitlab-ci.yml:
    build:
      script: ls
      stage: build
    
    test:
      script: ls
      stage: test
    
    deploy:
      script: ls
      stage: deploy
  2. Make this query in /-/graphql-explorer
    {
      project(fullPath: PROJECT_FULL_PATH) {
        pipeline(iid: PIPELINE_IID) {
          jobs {
            nodes {
              name
              previousStageJobs {
                nodes {
    	    name
                }
              }
            }
          }
        }
      }
    }
  3. See that you get the result:
{
  "data": {
    "project": {
      "pipeline": {
        "jobs": {
          "nodes": [
            {
              "name": "deploy",
              "previousStageJobs": {
                "nodes": [
                  {
                    "name": "test"
                  }
                ]
              }
            },
            {
              "name": "test",
              "previousStageJobs": {
                "nodes": [
                  {
                    "name": "build"
                  }
                ]
              }
            },
            {
              "name": "build",
              "previousStageJobs": {
                "nodes": []
              }
            }
          ]
        }
      }
    }
  }
}

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Avielle Wolfe

Merge request reports

Loading