title: How to get target branch hash in GitLab CI community edition?
body: <p>I've tried using <code>only: [merge_request]</code> as per the <a href="https://docs.gitlab.com/ce/ci/merge_request_pipelines/pipelines_for_merged_results/index.html" rel="nofollow noreferrer">documentation</a> to get <code>CI_MERGE_REQUEST_SOURCE_BRANCH_SHA</code> and <code>CI_MERGE_REQUEST_TARGET_BRANCH_SHA</code>. Unfortunately <code>declare -x</code> shows that <a href="https://gitlab.com/victor-engmark/pacman-package-file/-/jobs/865188694" rel="nofollow noreferrer">these variables are set but <em>empty</em></a> (<a href="https://gitlab.com/victor-engmark/pacman-package-file/-/blob/c9126464a7640ef145eaa38da2befe3611a8badd/.gitlab-ci.yml" rel="nofollow noreferrer">.gitlab-ci.yml file</a>). As far as I can tell, none of the <code>CI_</code> variables give this crucial information to work out the commit hash of the target branch.</p>
  <p>I've also tried with <code>except: [master]</code>, with <a href="https://gitlab.com/victor-engmark/pacman-package-file/-/jobs/865188385" rel="nofollow noreferrer">similar results</a> (<a href="https://gitlab.com/victor-engmark/pacman-package-file/-/blob/776e37650a42c4bd3ce930df9daad57113292766/.gitlab-ci.yml" rel="nofollow noreferrer">.gitlab-ci.yml file</a>).</p>
  <p>I've already looked at a <a href="https://stackoverflow.com/q/52746338/96588">similar Q&amp;A</a>, so I wonder if this might be a regression.</p>
  <p>As you can also see from the job output there are <em>no branches,</em> so I can't even use something like <code>master..HEAD</code>.</p>