Last active
August 17, 2023 12:28
-
-
Save fesor/9465dd9bb02741579fa2 to your computer and use it in GitHub Desktop.
Jenkins: script for checking is directory has changed from last build
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
#!/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 |
That's not the same at all:
GIT_PREVIOUS_COMMIT
SHA-1 of the commit used in the preceding build of this project
There can be multiple commits between two builds.
That's not the same at all:
GIT_PREVIOUS_COMMIT
SHA-1 of the commit used in the preceding build of this projectThere can be multiple commits between two builds.
Thx ! Avoiding lots of issues !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI:
GIT_PREVIOUS_COMMIT=$(git rev-parse --short "HEAD^")
GIT_COMMIT=$(git rev-parse --short HEAD)
So you don't have to rely on Jenkins