How to Manage Inter-Project Dependencies using Jenkins


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:
  1. 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.
  2. 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
  3. 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.

How to Set Java Home and Path in Linux

This small article will describe how to set the Java Path in Linux.

  1. Open '/etc/profile' file
  2. Add following line at the end of this file
    1. export JAVA_HOME=/usr/java/jdk1.6.0_33                                              export PATH=$PATH:/usr/java/jdk1.6.0_33/bin
    2. Change the path of JDK as per your installation
  3. This should set the path
  4. If it is not solving your problem, 
  5. Open '/etc/bashrc' file
  6. Add following line at the end of this file
    1. export JAVA_HOME=/usr/java/jdk1.6.0_33
      export PATH=$PATH:/usr/java/jdk1.6.0_33/bin
    2. Change the path of JDK as per your installation
  7. If it still does not resolve the motive,
  8. Open directory '/etc/profile.d'
  9. Create a file 'java.sh' here (if it is not there)
  10. Add following lines to this file
    1. JAVA_HOME=/usr/java/jdk1.6.0_33
      PATH=$JAVA_HOME/bin:$PATH
      export JAVA_HOME
      export PATH
Scripts located in 'profile.d' directory runs in the end and hence override any other settings done. So it should finally help to have the Java Home set in system.

How to Set Hostname for Linux Machine

Here is a small trick for defining a fix 'hostname' for linux machine. Sometimes we face a problem that 'hostname' keeps on changing for Linux machine. At first level, you can check with /etc/hosts, if settings are proper there. The contents should be like:

127.0.0.1               localhost.localdomain localhost
::1                          localhost6.localdomain6 localhost6

But sometimes, even after having these settings fine, we still face above problem.

Next level of quick fix for this problem is given below:

  • Open /etc/rc.local
  • Add following lines  in this file
  • hostname localhost.localdomain (or any other hostname if you want)
  • Save the file
  • Restart the system
This file runs in the last during network configuration (at the time of login) hence any setting which is written here will take effect finally. So whatever in your system would be affecting the hostname, will be overridden here. And you will get the right 'hostname'.