0
votes

I have repository structure

myproject/ ¦ ¦--jobs/ ¦ ¦--job1/{job1 directories & files} ¦ ¦--job2/{job2 directories & files}

And two Jenkins Jobs job1 for first path and job2 for second path. So if commit is on job1 directory path job1 should trigger and if commit is on job2 directory path job2 in Jenkins should trigger. But the problem is merge pull request is merged to master both jobs get triggered even commit is only one of job path.

2
Can you elaborate your question ? I got confused.smilyface
So, I have my repository structure as : myproject/ ¦ ¦--jobs/ ¦ ¦--job1/{job1 directories & files} ¦ ¦--job2/{job2 directories & files} And 2 Jenkins jobs configured for two separate paths one for job1 directory path one for job2 directory path. So if my pull request merge for commits in job1 directory or files job2 is also gets triggered.MAYUR KUMBHAR

2 Answers

0
votes

This is not a usual scenario. I think you have two ways.

  1. Have two separate repositories (Take commons and keep as a library) which is not so easy.
  2. Do a tweak in jenkins
  3. 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

0
votes

Found solution, Used ScriptTrigger plugin and wrote a script to while polling it will check commit for particular directory.