Unexpected empty skipped MR pipeline when CI is skipped preventing merges
<!--IssueSummary start-->
<details>
<summary>
Everyone can contribute. [Help move this issue forward](https://handbook.gitlab.com/handbook/marketing/developer-relations/contributor-success/community-contributors-workflows/#contributor-links) while earning points, leveling up and collecting rewards.
</summary>
- [Close this issue](https://contributors.gitlab.com/manage-issue?action=close&projectId=278964&issueIid=375786)
</details>
<!--IssueSummary end-->
## Summary
(Summarize the bug encountered concisely)
Starting with GitLab 15.2, a customer observes that an empty skipped MR pipeline is created when `[skip ci]` (or `-o ci.skip`) is used. This breaks the **Merge when pipeline succeeds** functionality because the most recent pipeline is `skipped`.
- It is possible to configure GitLab so that `skipped` pipelines are considered successful by **Merge when pipeline succeeds** (MWPS).
- This is not desirable because we want to know that a non-skipped pipeline completes successfully.
## Steps to reproduce
1. Create a project with `.gitlab-ci.yml` like what's shown below
1. Create an MR
1. Push a commit to the source branch with the merge request option to skip ci set
1. Observe that an empty skipped MR pipeline is created
### Example `.gitlab-ci.yml`
```
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: never
```
## Example Project
(If possible, please create an example project here on GitLab.com that exhibits the problematic
behavior, and link to it here in the bug report.
If you are using an older version of GitLab, this will also determine whether the bug has been fixed
in a more recent version)
## What is the current bug behavior?
An empty skipped MR pipeline is created.
## What is the expected correct behavior?
The behavior observed prior to GitLab 15.2 should be restored:
- the empty skipped MR pipeline should not be created
## Relevant logs and/or screenshots
(Paste any relevant logs - please use code blocks (```) to format console output, logs, and code, as
it's very hard to read otherwise.)
## Possible fixes
The customer points out the MRs linked below with this note:
> The changes were to add support for push options being passed into merge request pipelines: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/87030 and https://gitlab.com/gitlab- org/gitlab/-/merge_requests/87323. The issue seems to be that the order in which the pipeline is built means that skip is evaluated before the workflow rules: https://gitlab.com/gitlab- org/gitlab/-/blob/master/app/services/ci/create_pipeline_service.rb#L25 (line 19 and 25). Now that push options are
passed through it now decides the pipeline needs to be skipped before it gets as far as evaluating workflow rules.
### Similar Issues
- The [Skipping pipelines commit option does not work for merge request pipelines OR merged results pipelines](https://gitlab.com/gitlab-org/gitlab/-/issues/27955) issue is _similar_ and potentially related but does not capture the specific undesired behavior that the customer is experiencing.
- https://gitlab.com/gitlab-org/gitlab/-/issues/328076
## Workaround
The customer is presently working around this problem with the following approach which may be of use to others who are impacted by this problem:
- When committing, include `-o ci.variable=CI_SKIP=true`
- Modify `.gitlab-ci.yml` to include:
```
- if: $CI_SKIP
when: never
```
## :books: Docs
- [Push options for GitLab CI/CD](https://docs.gitlab.com/ee/user/project/push_options.html#push-options-for-gitlab-cicd)
issue