Display downstream pipeline errors in upstream pipelines (UX improvement)
### Summary When triggering downstream pipelines they can error out. We should be able to display these errors in the upstream bridge job. ![Screen_Shot_2020-04-07_at_15.07.38](/uploads/ae6f82782d8284b948c96f473cc4daa3/Screen_Shot_2020-04-07_at_15.07.38.png) ### Proposal We can reach failure reasons of downstream pipelines via `Ci::Bridge#sourced_pipelines`. However, we don't always create downstream pipelines. Examples: - https://gitlab.com/gitlab-org/gitlab/-/blob/12-9-stable-ee/app/services/ci/create_cross_project_pipeline_service.rb#L52 After implementing #213666, in this issue, we need store failure reason information of downstream pipelines in bridges. (More discussions about it: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/28120#note_312091893) Then we can have this behavior: ![Screen_Shot_2020-03-26_at_17.49.17](/uploads/61a993c569ffe152bda5dd15c5393764/Screen_Shot_2020-03-26_at_17.49.17.png) --- We also need to add failure reason for strategy:depend situations. We may do this in another issue/MR. Discussion: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/28120#note_318999395 > I would also consider adding `downstream_pipeline_failed` failure reason to a the list of failure reasons supported by `Ci::Bridge`. It seems like a small effort, and might improve the situation here significantly. We probably would need to add this to `self.drop!(...)` in `Ci::Bridge#inherit_status_from_downstream` --- <details> <summary>Old Proposal</summary> 1. Persist all pipeline creation errors in `Ci::Pipeline` model. Maybe we can reuse `Ci::Pipeline#yaml_errors` and rename it to `Ci::Pipeline#creation_errors`? 1. When creating a downstream pipeline we now persist always the association between bridge job and downstream pipeline, so we can always reference the downstream pipeline from the bridge job. 1. Change `Gitlab::Ci::Status::Build::Failed#failure_reason_message` to append related downstream pipeline errors if `failure_reason_message` is called to display bridge job errors. We could look into changing the `failure_reason_message` to append any additional errors from the downstream pipeline. ```ruby class Ci::Status::Build::Failed def failure_reason_message messages = [] messages << self.class.reasons.fetch(subject.failure_reason.to_sym) messages += subject.additional_errors messages.join(', ') end end class Ci::Bridge def additional_errors return [] unless failure_reason == 'downstream_bridge_pipeline_creation_failed' # this is not performant and queries need to be optimized sourced_pipelines.map do |source_pipeline| source_pipeline.pipeline.yaml_errors end end end class Ci::Build def additional_errors [] end end ``` </details> <details> <summary>Technical Background</summary> ``` When triggering a downstream pipeline with a bridge job - if the downstream pipeline creation errors out (e.g. an invalid YAML config), the relationship between the bridge job and the downstream pipeline is not saved. This is because the relation is being added in the `Seed` pipeline chain step and the chain is broken in `Confing::Content` or `Config::Process` which comes before `Seed`. This is required for displaying the downstream creation errors in upstream bridges. ``` This was resolved with https://gitlab.com/gitlab-org/gitlab/issues/207234 </details> ### Use cases to solve - https://gitlab.com/gitlab-org/gitlab/issues/204378 - https://gitlab.com/gitlab-org/gitlab/issues/198354
issue