title: How do I make sure on_stop runs in a pipeline if the step using the keyword fails?
body: <p>I have a step in a pipeline that creates a MR environment and then when the MR is merged tears down the MR environment using the <code>on_stop</code> keyword.</p>
  <p><em>Example step</em></p>
  <pre class="lang-yaml prettyprint-override"><code>deploy-mr-env:
    rules:
      - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
        exists:
          - helm/config/values-sandbox.yml
    extends:
      - .deploy-mr-env-base
    variables:
      HELM_SANDBOX_CONFIGS: &gt;-
        -f helm/config/values-sandbox.yml
        -f helm/config/secrets-sandbox.yml
    environment:
      name: ${MR_ENVIRONMENT}
      url: https://${CI_PROJECT_NAME}-mr${CI_MERGE_REQUEST_IID}.sandbox.com
      on_stop: stop-mr-env
  
  
  </code></pre>
  <p>The bug we found with our pipeline looks like this:</p>
  <ul>
  <li>A MR is created and a MR environment is stood up.</li>
  <li>Changes are made based on what is discovered with the MR env deployment.</li>
  <li>A change is pushed to MR branch (kicking off the pipeline) prior to the MR being merged, some anomalous event occurs on the cloud platform used to host the MR env, and the <code>deploy-mr-env</code> step fails (i.e. - <code>oc login</code> command fails for some weird reason).</li>
  <li>MR is merged.</li>
  <li>Because <code>deploy-mr-env</code> failed when the last changes were pushed to MR branch <code>on_stop</code> doesn't run.</li>
  </ul>
  <p>Normally <code>on_stop</code> runs when a MR is merged, but this is a weird little edge case in our pipeline. How would we make sure <code>on_stop</code> runs during a merge event even if the <code>deploy-mr-env</code> step failed the previous time changes were pushed to the MR branch?</p>