"Merge When Build Succeeds" merges even on failed build

Summary

For builds that are ran with specific order types, the merge occurs once the first stage passes even if later stages are failures which can lead to unexpected results and failing builds being merged.

Steps to reproduce

  1. Create blank project.
  2. Add successful .gitlab-ci.yml to repo
  3. Push master branch
  4. Create new branch
  5. Update .gitlab-ci.yml to add subsequent failing build
  6. While build is running click "Merge When Build Succeeds"
  7. First stage will pass and merge will complete
  8. After merge second stage will fail

I have noticed similar behavior with webhooks and using them to trigger deployments, since each stage fires its own webhook and one could pass and then later ones fail.

This problem does not seem to occur unless a specified order is in the build. If the build is not ordered with the type option or has only one type then the merge does not complete until all stages have passed.

I have not tested on latest master because I have not quite determined how to run a ci-runner locally. I tested with the build on gitlab.com as of 2016-02-01 @ 17:15 CST. I ran against latest master locally and still an issue.

Expected behavior

The branch should not be merged until all stages (without allowed_to_fail) pass.

Relevant logs and/or screenshots

Working .gitlab-ci.yml

types:
  - one
  - two
job1:
  type: one
  script:
    - echo "should pass"
    - ls

Failing .gitlab-ci.yml The sleep helps simulate longer build and allows time to click "Merge When Build Succeeds"

types:
  - one
  - two
job1:
  type: one
  script:
    - sleep 30
    - echo "should pass"
    - ls
job2:
  type: two
  script:
    - echo "should fail"
    - cat not_here

Merge Accepted and Waiting Merge has been accepted and is waiting for build to succeed. Merge Accepted and Waiting

Branch Merged Branch has been merged even though second stage is still running Branch Merged

Build Failed after Merge Branch has been merged and afterwards the build fails Build Failed after Merge