We have explained about Use of Jenkins and its Configuration in one of the previous blog. Here we shall discuss, how Jenkins can be used to work with inter-dependent projects. Managing the CI environment with multiple inter-dependent projects is quite important, as it is general scenario with projects.
If there are multiple projects having dependencies, then requirements would be:
- If Project A is dependent on Project B, then a successful build of Project B should trigger the build for Project A also. In generic words, the build of current project should trigger the build for other dependent projects also. It is required to ensure the integrity of whole project dependency chain after any change.
- The dependent projects should be able to pick the latest jars from Projects on which these are dependent. Different mechanism can be used for this. One of these could be to modify the build system of every dependent project to pick the required jars from downstream project
- This way, finally whole project chain will be built again on change in any of the project (from down to up)
Now, how we can achieve these requirements in Jenkins. Here we are describing this with an example.
- Suppose there are three projects, Project 1, Project 2 and Project 3.
- Project 1 is dependent on Project 2. Project 2 is dependent on Project 3.
- Assumption is that build of every project produce the distribute-able jar etc in a specific folder
- Now update the 'build' for Project 3 in a way, so that before compiling its own code base, it picks the output of Project 2 build from its output folder and synchronize it in its own library folders. Of course, assumptions are to have a fixed project structure (preferably relative directory structure).
- Similarly update the 'build' for Project 2 in a way, that before compiling its own code base, it picks the output of Project 1 'build' from its output folder and synchronize it in own library folders.
- Create a Job in Jenkins for Project1, as described with previous article
- Add post build actions to this job to trigger the build of Project2
- Create a Job for Project2
- Add post build actions to this job to trigger the build of Project 3
- Create job for Project3
- Using this setup, whenever Project1 will be build, it will trigger the job for Project2
- Project 2 will pick the depdencies from Project1 output folder and will build its own code base. Build will place the output files in some specific folder.
- Similarly Project3 build will be triggered and it will pick the dependencies from Project2 output folders
Using this approach, we shall be able to have a perfectly integrated build system and will be able to track if any of the project in whole dependency chain breaks due to any commit. On change in any project, it will trigger the build of all dependent projects. Inter-project dependencies will be synchronized automatically.