Skip to content

GraphQL method previousStageJobsOrNeeds returns empty value if there are no jobs in previous stage

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Summary

We want to use graphQL functionality for building pipeline dependencies graph.

Analogically, like you use it in pipeline job dependencies. But we met a weird bug.

If there is stage without jobs, between two jobs in another stages (before and after empty stage), then graphQL returns empty previousStageJobsOrNeeds.

Steps to reproduce

  1. Create CI/CD configuration
stages:
  - stage1
  - empty1
  - stage2
  - empty2
  - stage3

job0:
    stage: .pre
    script: echo test
job1:
    stage: stage1
    script: echo test
    needs: []
job2:
    stage: stage2
    script: echo test
job3:
    stage: stage3
    script: echo test
  1. Go to graphql-explorer and run:
{
  project(fullPath: "madest92/empty-needs") { # replace to your project name
    pipeline(iid: "1") {                      # replace to your pipeline IID
      jobs {
        nodes {
          name
          stage {
            name
          }
          needs {
            nodes {
              ... on CiBuildNeed { iid:id, name }
            }
          }
          previousStageJobsOrNeeds{
            nodes {
              __typename
              ... on CiBuildNeed { iid:id, name }
              ... on CiJob { id, name }
            }    
          }
        }
      }
    }
  }
}

Example Project

https://gitlab.com/madest92/empty-needs/-/pipelines/946376722

What is the current bug behavior?

We see empty previousStageJobsOrNeeds for all jobs. Because of previous stage empty1, empty2, which actually has no jobs.

pipe-deps graphQL-empty-deps

There is another feature in graphQL: CiJob.needs, but it doesn't allow to understand:

  1. Job has no needs
  2. Job doesn't depend on another jobs

CiJob.needs would be empty for job1 and job0.

What is the expected correct behavior?

We expect, that in graphQL job3 depends on job2 and job2 depends on job1

If we remove empty stage and keep only these:

stages:
  - stage1
  - stage2
  - stage3

It works as should.

graphQL-ok

Output of checks

This bug happens on GitLab.com

Edited by 🤖 GitLab Bot 🤖