Reuse one Jenkins jobs for multiple Git (GitHub) repositories

2.3k views Asked by At

I have a very simple Jenkins build which is needed for several repositories. All these repositories have the same organisation, the same branches, etc. There is no difference except the repository name.

Each single repository should be able to trigger the build for only this specific repository. I imagine something like combining a parameterized build with a WebHook URL containing a query parameter for the repository name maybe.

Any ideas or pointers about that?

4

There are 4 answers

1
Guite On BEST ANSWER

After having done a bit more research I think I will try the "GitHub Organization" job type. It scans all repositories for a given GitHub organization or owner and automatically manages corresponding jobs.

0
Michael On

Somewhere I read about an organization where they put most standard pipelines into comprehensive shared libraries. This article is quite a good read about that.

My own company uses "Seedjobs" to create multiple pipelines with only one job. Read this article for an overview on that idea.

0
Harshavardhan Konakanchi On

We had achieved it through creating Jenkins build templates and configuring each job for each url based on this template

We can have one job configured with parameters, but didn't go for that approach as that is not that easy to know for which git repo it is failing as we need to go through parameters of each build

Templates can be created using the following plugin https://wiki.jenkins.io/display/JENKINS/Template+Project+Plugin

0
pppai On

I know this question is already answered, but there is another simple way of triggering a single Job from multiple GitHub URLs.

You could use Generic Webhook Trigger Plugin to build same Job from different GitHub repositories. You need to assign unique token to the Job and configure the Webhook of multiple GitHub repositories as:

JENKINS_URL/generic-webhook-trigger/invoke?token=TOKEN_NAME