Fix pipeline throwing error when needs is undefined
What does this MR do?
Using a pipeline with optional needs causes rendering errors in the pipeline view. This is because if you have an optional job which condition is false
, then that job doesn't exist as far as the frontend is concerned. But, another job might reference in their need the non-existent job which we have not taken into account in our algorithms. This MR fixes this problem and add some spec coverage for it.
Issue: #330602 (closed)
Sentry log: https://sentry.gitlab.net/gitlab/gitlabcom-clientside/issues/2591827/?query=is%3Aunresolved
This was the thrown error:
instrument.js:109 TypeError: Cannot read property 'needs' of undefined
at parsing_utils.js:79
at Array.map (<anonymous>)
at t (parsing_utils.js:78)
at parsing_utils.js:108
at Array.filter (<anonymous>)
at h (parsing_utils.js:92)
at g (parsing_utils.js:115)
at b (parsing_utils.js:158)
at a.getPipelineLayers (graph_component_wrapper.vue:190)
at a.<anonymous> (graph_component_wrapper.vue?c440:1)
at a.t._render (vue.esm.js:3557)
at a.r (vue.esm.js:4075)
at mn.get (vue.esm.js:4488)
at mn.run (vue.esm.js:4563)
at pn (vue.esm.js:4319)
at Array.<anonymous> (vue.esm.js:1989)
at Jt (vue.esm.js:1915)
Screenshots (strongly suggested)
header | After |
---|---|
Screen_Recording_2021-05-18_at_1.31.04_PM | Screen_Recording_2021-05-18_at_12.07.25_PM |
Does this MR meet the acceptance criteria?
Conformity
-
I have included a changelog entry, or it's not needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) - [-] I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?)
- [-] I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?)
-
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides.
Availability and Testing
- Create a pipeline with optional needs like this for example:
stages:
- stage1
- stage2
job1:
stage: stage1
script:
- echo "job1"
rules:
- if: $CI_COMMIT_REF_NAME != "master"
job2:
stage: stage2
needs:
- job: job1
optional: true
script:
- echo "job2"
- Go into the pipeline view of that run and click "Group jobs by Job dependencies"
Example Project
https://gitlab.com/WIStudent/needs-optional-gitlab-ui-issue-demo/-/pipelines/300869103
What is the current bug behavior?
The ui shows an indefinte loading animation. "Group jobs by" buttons also might not be rendered at all if you already switched to "Job dependencies" in a previous pipeline run where the optional needs did not exist or the optional job was included.
What is the expected correct behavior?
Job dependency graph should be rendered.
Security
Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Related to #330602 (closed)