16

My repo has multiple projects in subfolders with same structure duplicated across multiple branches.

I'm trying to set up a job that monitors all branches and triggers a job only when a change in a subdirectory 'Project1' is made. This way I can check if changes to 'Project1' work on release branches and any dev branches people might set up.

In theory it seems the Git plugin does let me set this up, by specifying '**' in 'Branches to build' and 'Project1.*' in 'Included Regions'. I also use 'Poll SCM' since that seems to be a prerequisite.

This works fine as long as you make changes only to one branch. Once you make a change outside of the 'Project1' folder on another branch, Jenkins picks up a changes from any directory.

Is this a bug or am I trying to do something that is not supported?

JaSn
  • 209
  • 1
  • 2
  • 8

2 Answers2

2

It`s possible, but not recommended. You can set additional checkout behavior and then choose which folders should trigger the build and which are not.

enter image description here

whitediver
  • 462
  • 3
  • 12
0

I think that this answer can help you. You only need to implement the hook with the logic which project to build

Community
  • 1
  • 1
Yuri G.
  • 4,323
  • 1
  • 17
  • 32
  • Creating this per project will not be easy to maintain, given that I will have a large number of jobs eventually. I'm interested how to make the currently available options work. – JaSn Apr 22 '15 at 17:40
  • Hmmm.... May be I missed something... You have 1 git repo with all your projects as a subfolders, right? So as mentioned in the [answer](http://stackoverflow.com/questions/12794568/how-to-configure-git-post-commit-hook/12794930#12794930) you can use the ["Push based builds using Jenkins and GIT"](http://blog.avisi.nl/2012/01/13/push-based-builds-using-jenkins-and-git/) to trigger your jobs. All you need to do is to write a 1 post-receive hook that implements the logic which job with which parameters should run – Yuri G. Apr 22 '15 at 19:32
  • I am anticipating a large number of jobs created by my users, so I cannot predict the project names they will use. From what I understand, the linked solutions require me to know the Jenkins project names. If that's not the case, let me know what I'm missing. – JaSn Apr 22 '15 at 22:18
  • got your point. did you try the option "Polling ignores commits in certain paths"? the tooltip says _If set, and Jenkins is set to poll for changes, Jenkins will pay attention to included and/or excluded files and/or folders when determining if a build needs to be triggered._ – Yuri G. Apr 23 '15 at 22:22
  • Yes, I have includes set up. Setting excludes will make maintenance harder. I think this might be some sort of a bug. I've debugged the Git plugin and I see that the git command itself is returning incorrect results. Created another question specifically for that [here](http://stackoverflow.com/questions/29835309/see-git-a-list-of-all-commits-that-went-between-two-commits-across-branches) – JaSn Apr 23 '15 at 22:33