Skip to content

Instantly share code, notes, and snippets.

@mendes5
Last active January 10, 2022 12:48
Show Gist options
  • Select an option

  • Save mendes5/1a2774dcf2ca6d05a9801eebdcb4db54 to your computer and use it in GitHub Desktop.

Select an option

Save mendes5/1a2774dcf2ca6d05a9801eebdcb4db54 to your computer and use it in GitHub Desktop.
How to skip a GitLabCI job from a before_script
build-job:
before_script:
- |
if [[ "${CI_COMMIT_BRANCH}" != "${CI_DEFAULT_BRANCH}" ]]; then
git fetch origin $CI_DEFAULT_BRANCH
SKIPPABLE_CHANGES=`git diff origin/$CI_DEFAULT_BRANCH --name-only $SKIP_SOURCE_STAGES_FOR_DIRS`
ALL_CHANGES=`git diff origin/$CI_DEFAULT_BRANCH --name-only`
if [[ $SKIPPABLE_CHANGES == "" ]]; then
echo "There were no skippable changes, the script will continue"
elif [[ $SKIPPABLE_CHANGES == $ALL_CHANGES ]]; then
echo "All changes detected are inside a folder marked as skippable, the script will not continue"
exit 0
fi
fi
script:
echo "Run some heavy script that doesnt depends on anything inside of SKIP_SOURCE_STAGES_FOR_DIRS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment