Inconsistent application of `if: $CI_MERGE_REQUEST_APPROVED == "true"` job rule when MR approval status changes
Summary
When an MR is first created which requires approval to merge, a job with a rule based on if: $CI_MERGE_REQUEST_APPROVED == "true"
does not get created as the MR is not in an approved state.
If the MR is then approved, and a subsequent code change made which requires MR re-approval, a pipeline containing the job is created, despite the MR now being in an unapproved state.
It appears that after the change is pushed the pipeline is evaluated before the MR approval state is set back to unapproved, despite the intention being for the job not to be able to run unless the MR is in a final approved state. This may be related to the order in which async sidekiq jobs are executed.
Steps to reproduce
-
create a project configured to require MR approval from a different user.
-
create a pipeline configuration as follows:
deploy_job: script: - echo "Manual deployment" rules: - if: $CI_MERGE_REQUEST_APPROVED == "true" when: manual - when: never
-
create a new branch in the project containing a new dummy file and create an MR for the change.
-
note that the MR requires approval, and no pipeline is created
-
approve the MR - still no pipeline is created since MR approval is not a pipeline triggering event
-
now from the MR diffs page edit the new file and make a change to it, and save
-
after a short time the MR goes back to being in an unapproved state, but in the meantime a pipeline is started containing the job, which can be manually started
Example Project
https://gitlab.com/jfarmiloe_ultimate_group/issue-429470
What is the current bug behavior?
After a new change is made in the MR a pipeline and job is scheduled despite MR now being in unapproved state.
What is the expected correct behavior?
New MR approval state should be set before pipeline scheduling takes place, so that no pipeline/job is scheduled after a subsequent change is made.
Relevant logs and/or screenshots
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: \\\`sudo gitlab-rake gitlab:env:info\\\`) (For installations from source run and paste the output of: \\\`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production\\\`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of: \`sudo gitlab-rake gitlab:check SANITIZE=true\`) (For installations from source run and paste the output of: \`sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true\`) (we will only investigate if the tests are passing)