According to the documentation:
You cannot use nested variables with if.
if
So because $COMPARE_BRANCH is supposed to resolve to $CI_COMMIT_BRANCH that's where my problem is. There's an open issue to address this.
$COMPARE_BRANCH
$CI_COMMIT_BRANCH