Reputation: 23
I would like to run jenkins job when the specific folder in Git/Git-hub master branch changes.
Currently its running whenever Git master is changing but i need only when the specific folder is changing within the Git master than only its supposed to run.
As I mentioned above,only subFolder changes than only I need to run the job,i tried with different options but its unable to identifying my folder.
Looking for you advice and solutions.
Thanks for advance.
Upvotes: 0
Views: 1829
Reputation: 23
I got the answer to this question by adding one simple Additional behavior to the Jenkins i.e. just check 'Additional Behaviors' section below the Git section and choose 'Polling using specific folder path' that's it.
Now give the specific folder path whatever you want - in my case 'subFolder/*.sh'
Upvotes: 0
Reputation: 111
One hack I can think of is in your jenkins test script, first read the latest commit (use the GIT_COMMIT environment variable), and scan for any change in the target sub-directory you care about. If no change shows up, then just terminate the build early.
It is not pretty, but should work in your scenario.
Example:
git diff --name-only $GIT_PREVIOUS_SUCCESSFUL_COMMIT $GIT_COMMIT | grep "the/directory/you/care/" -q
if [ $? -ne 0 ]; then
# if there is no change under the directory you care, exit now.
echo "No change under the target directory. Skipping build.."
exit 0
fi
# your existing build/test script...
Upvotes: 2