Last active
January 10, 2022 12:48
-
-
Save mendes5/1a2774dcf2ca6d05a9801eebdcb4db54 to your computer and use it in GitHub Desktop.
How to skip a GitLabCI job from a before_script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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