Repeatable Jenkins Jobs for Multiple GitHub Repos
I was recently listening to a podcast from devtools.fm and monolithic repos were brought up, and one of arguments for them, was that it is hard to do CI/CD for lots of repos. In this post we are going to talk about a couple different ways to easily manage CI/CD jobs for hundreds of repos, relatively easy, with either Github Actions or Jenkins.
Let’s talk about Jenkins. First, if you are not using shared libraries, you should be, and there will be another blog post about those later. Now for the plugin, we use Github Branch Source Plugin which can scan all repos for an organization or user, and based on a file in the repo, run a certain pipeline from a completely different repo. This is where some thought needs to used to come up with a naming schema for the files in the repos.
We use something like this:
- Jenkinsfile.config – File in the repo that holds environment variables loaded in the pipeline, and the file that is looked for, for the Pull Request jobs in the Github Org plugin.
- Files linked to Jenkinsfile.config
- Jenkinsfile.S3.config – Tells the Github Org plugin in Jenkins to run the S3 jobs.
- Jenkinsfile.NODE.config – Tells the Github Org plugin in Jenkins to run the NODE jobs.
Example content
Now all you need to do is create your Jenkinsfile pipelines and make sure you read in the Jenkinsfile.config to set your environment variables.
Example of pipeline
Here is what the Github Org Plugin in Jenkins would look like for Pull Requests.
Here is what the Github Org Plugin in Jenkins would look like for builds that go to S3
With the above examples setup, it allows the developers of the repo’s to have some control of the CI/CD jobs as they can easily make changes to the Jenkinsfile.config file. We use this setup for an organization with over 200 repositories for all our pull requests, builds, and deploy jobs and over a dozen different pipelines for S3, Node, Ansible, .net, ASP, and Lambda. With this setup, it is very easy to add a new pipeline or support a new language, maybe 15 minutes more of work vs adding a custom pipeline to a single repo.