This is not a usual scenario. I think you have two ways.
- Have two separate repositories (Take commons and keep as a library) which is not so easy.
- Do a tweak in jenkins
- Write a same kind of logic (as below) in your repository if possible.
Here is one way to achieve this in jenkins (my point 2).
One problem is : Two jenkins will get started, but one will be terminated without completing the jenkins-job.
You can write a bash script for this.
The logic in JOB-1 is to terminate if committed files are under job2 directory and same for JOB-2 (terminate if files are from job2 dir)
Add this script and run (as first) Job-1 jenkins
#!/bin/bash
# Get count of job2 directory files
count_of_job2_files=`git show --pretty="format:" --name-only <commitID> | grep "job2/" | wc -l`
# if Job2 dir files are more than 0 then termiate the jenkins job
[ $count_of_job2_files -gt 0 ] && exit 0 ;
Add as same kind of script in job2 jenkins.
Note:
The logic is written assuming you use git as the repository