Skipped a job when before_script fails

:hugs: Please help fill in this template with all the details to help others help you more efficiently. Use formatting blocks for code, config, logs and ensure to remove sensitive data.

Problem to solve

I use Gitlab CI/CD to run ansible playbooks with my custom gitlab runner.

I would like my job first to check if the “git diff” fails, and if it fails, then skip running the ansible playbook.
The way I have it now, it shows in the Pipeline with a warning because of the “allow_failure: true”
But I would like to be able to skip the job based on the git diff results.

Steps to reproduce

Which troubleshooting steps have you already taken? Can you link to any docs or other resources so we know where you have been?


Run Ansible-playbook to Remove records:
  stage: removing
    - cd /ansible/builds/6ss-CqweB/0/dns/dns-test
    - git diff HEAD~1:myzone.internal myzone.internal | egrep "^\-([*][.]\w+|[*]|[@]|\w{1,})"
    - cd /ansible
    - ansible-playbook dns-removing-records.yml -e "folder_path=$CI_PROJECT_DIR file_name=$FILENAME_INTERNAL zone=${zone} key_name=${key_name} key_secret=${key_secret}"
  allow_failure: true


Please select whether options apply, and add the version information.

  • Self-managed
  • SaaS
  • Self-hosted Runners


  • GitLab (Web: /help or self-managed system information):
    Version: 16.7.7
  • GitLab Runner, if self-hosted (Web /admin/runners or CLI gitlab-runner --version):
    Version: 16.6.1

Helpful resources

  1. Before opening a new topic, make sure to search for keywords in the forum search
  2. Check the GitLab Runner and GitLab projects for existing issues. If you encounter a bug, please create a bug report issue.
  3. Troubleshooting docs: GitLab Runner, self-managed GitLab instances.

Thanks for taking the time to be thorough in your request, it really helps! :blush: