4

I have one standard Jenkins job that needs to be triggered for any pull request/commit made to any of the x repository I've added to the multiple SCM plugins in the configuration.

Is there any way to have a hook on all the repos so that on a pull request to any of the repos the job builds the specific repo where the pull request was made?

This would be helpful as I would not need 1 job per repo when I can have one job for all the repos.

StephenKing
  • 36,187
  • 11
  • 83
  • 112
Scooby
  • 3,371
  • 8
  • 44
  • 84

2 Answers2

3

If you set your Jenkins url in the webhooks and services of your various GitHub repos, Jenkins will be called by that webhook.

But the Jenkins GitHub plugin will only trigger the job where "Github project" has the right git@github.com:Person/Project.git repo.

One possible workaround would be to:

  • publish on GitHub one parent repo which declares all the other ones as submodules;
  • set another webhook on those other repos in order to trigger a git submodule update --remote within the parent repo (in order to refresh all the submodules gitlinks SHA1, special entries in the index) and push that parent repo back to GitHub;
  • have a Jenkins job which monitor (through GitHub plugin and its webhook) that sole GitHub parent repo;
  • have a build step which compares GIT_COMMIT and GIT_PREVIOUS_COMMIT in order to determine which subfolder -- submodule -- has just changed, and launch a build only on that or those subfolders.
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
-1

It is possible by using Jenkins Pipelines.

You could specify any number of SCM locations via checkout built-in step. In this case Jenkins would "know" that it has to rebuild the pipeline upon modification in any of the source repositories. Git hooks should be enabled to make it happen of course.

Dmitry Buzdin
  • 1,233
  • 1
  • 9
  • 15
  • Do you mean something other than the MultiBranch Pipeline plugin? Because that will only trigger on webhooks to the repo that contains the Jenkinsfile. – Jason Antman Mar 23 '21 at 13:03