Reputation: 1434
On a Jenkins build I'd like to skip some tests if a part of the repository hasn't changed. This could save a lot of time on the build process. Here's how I can do it on my dev machine:
changes=$(git log --name-only --pretty="" my_branch..HEAD | grep path/to/folder)
if [[ -z $changes ]]; then
echo "no changes detected, skipping tests"
exit 0
fi
echo "running tests!"
How do I do this on a Jenkins machine?
I'm using a git
plugin for Jenkins and it can figure my branch name with $GIT_BRANCH
, but I'm clueless how to get a list of file changes on my build.
Upvotes: 0
Views: 1678
Reputation: 5321
In a Freestyle job, you will probably have to use the conditional build step plugin. I don't think you can run a shell script as one of the conditions, but you can run one step to execute your shell script you pasted, and have it touch a file if you should (or should not) run a test. Then use the Conditional Build Step to look for that file and do the right thing.
I also just realized that one of the Additional Behaviors that the git plugin has is Polling ignores commits in certain paths. This allows you to specify includes or excludes. If you specify the "Includes" the job won't even trigger a build at all if files other than those are modified. Then you don't even need your shell script or to take up an executor to check the changes.
Upvotes: 1