Last active
December 20, 2015 00:39
-
-
Save drkibitz/6043416 to your computer and use it in GitHub Desktop.
jenkins conditional to check if push is allowed
This file contains 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
# Rebase any commits on top of anything new from remote | |
git pull --rebase $UPSTREAM_GIT_REMOTE $UPSTREAM_GIT_BRANCH | |
# get the tracking-branch name | |
tracking_branch=$(git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)) | |
# creates global variables $1 and $2 based on left vs. right tracking | |
# inspired by @adam_spiers | |
set -- $(git rev-list --left-right --count $tracking_branch...HEAD) | |
behind=$1 | |
ahead=$2 | |
if [ $behind -gt 0 ] || [ $ahead -lt 1 ]; then | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment