One Jenkinsfile for multi project git repository

Viewed 3300

My developers team want to use a single GIT repo to store several microservices as it is more convenient to only synchronise one repo.

Unfortunately, all Jenkins pipeline litterature i've found always show a Jenkinsfile at the root of a repo holding only one microservice.

If we consider the following git repository structure:

MyProject
         ¦-> Microservice1
         ¦                ¦-> src/main/java/...
         ¦                ¦-> src/main/docker/Dockerfile
         ¦
         ¦-> Microservice2 (etc.)
         ¦-> Microservice3 (etc.)
         ¦
         ...
         ¦-> Jenkinsfile

How can I detect inside the jenkinsfile which Microservices projects were updated in order to execute de pipeline on those projects only?

2 Answers

I don't know if you are somehow restricting yourself via the blue ocean UI, but if you set up a pipeline job via the traditional UI, the jenkinsfile to run is a parameter.

Actually the whole scenario is pretty flexible, much more than it may first appear. I maintain a system where there are about 20 interdependent modules. I have several different build trigger scenarios, depending if I want to build a module isolated or rebuild dependent modules, and whether the jobs are triggered from gitlab (which we use) or are manual. I don't want to maintain multiple copies in each repo.

What I've found I can do is to have yet another repo which contains the Jenkins stuff - it is a shared library as well as containing several effective Jenkinsfile and sub-scripts I use via load(). The Jenkins files loads the relevant real repo and does the appropriate build Job.

Related