In your case, 'included region' feature from Git plugin should help. See this answer for details.
So, for pipeline, you can generate the correct syntax using pipeline-syntax generator (under http://<JENKINS_IP>:<JENKINS_PORT>/job/<PATH_TO_PIPELINE_JOB>/pipeline-syntax/
job in Sample Step: checkout -> SCM: Git -> Additional Behaviours -> Polling ignores commits in certain paths). It will be something like this:
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'PathRestriction', excludedRegions: '', includedRegions: 'migrations/.*']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'test', url: 'http://test.com/test.git']]])
Check this documentation for details (extensions -> includedRegions
).
For job dsl syntax it will be like this:
scm {
git {
remote {
...
}
extensions {
cleanBeforeCheckout()
disableRemotePoll() // this is important for path restrictions to work
configure { git ->
git / 'extensions' / 'hudson.plugins.git.extensions.impl.PathRestriction' {
includedRegions "somepath/.*"
excludedRegions "README.md\n\\.gitignore\npom.xml"
}
}
}
}
}
Also, you can use GitHub/GitLab/BitBucket webhooks to build a project when a change is pushed to repository.
See this example for Github and BitBucket configuration and this example for GitLab configuration.
If you want to build the project only for changes in migrations
folder and not for any changes in repository, you can configure comment regex for triggering a build and add this specific comment (e.g., "[changes in migrations folder]") to the commit every time you want to trigger a build.