Skip to content

Instantly share code, notes, and snippets.

@samuelematias
Forked from fesor/script
Created July 7, 2020 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuelematias/754535c38de9931df74dfad13dd81ae0 to your computer and use it in GitHub Desktop.
Save samuelematias/754535c38de9931df74dfad13dd81ae0 to your computer and use it in GitHub Desktop.
Jenkins: script for checking is directory has changed from last build
#!/bin/bash
DIR_PATH=$1
if [ ! -d "$DIR_PATH" ]; then
echo "Directory '$DIR_PATH' not exists"
exit 1
fi
if [ -z "$GIT_COMMIT" ]; then
echo "No current commit... fail"
exit 1
fi
if [ -z "$GIT_PREVIOUS_COMMIT" ]; then
echo "No previous commit, files are changed!"
exit 0
fi
# Check is files in given directory changed between commits
# NOTE: $GIT_PREVIOUS_COMMIT and $GIT_COMMIT provided by Jenkins GIT Plugin
CHANGED=`git diff --name-only $GIT_PREVIOUS_COMMIT $GIT_COMMIT $DIR_PATH`
if [ -z "$CHANGED" ]; then
echo "No changes dettected..."
else
echo "Directory changed"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment