I have several Jenkins Job running which Deploy’s code to application server. These jobs run automatically whenever there is Commit in Github repository configured through Jenkins Plugin in Github and webhook. Jenkins is running on a Windows system.
We have several applications in the repository, represented by a directory containing the code, each of these applications have a corresponding Jenkins Job which deploy’s the code to server when the Job is run.
Since all the applications are in the same repository, so change in any one of the application creates a Push event and thus trigers all the Jobs.
Suppose there are three Applications App1, App2 and App3 and their corresponding Jobs are J1, J2, J3
and there is a change in App1 and a commit is made in Github repository it causes all the Jobs J1,J2,J3 to trigger and Deploys App1, App2, App3 in server.
It causes unnecessary confusion since App2, App3 do not have any changes in repository but still gets deployed to server.
Is there any way that i can trigger specific Jenkins job build based on Directory level Changes/Commits in the Github repository. Can we use any git hooks somehow to achieve this?
There is one alternative.
Keep a separate folder which is the copy of the previous version of code.
When your jobs starts, keep a condition logic to check the folder contents as a whole.
If there are any changes(Hope you are cleaning the repository folder from binaries generated), then only that should trigger that particular build step.
For folder compare, there are many API’s for any scripting language.
Sounds like you have build pipeline with J1 as upstream for J2/J3 (assuming J2/J3 gets parallel trigger and not J2 as second upstream for J3).
In this scenario, there will be no impact to J2/J3 applications as there is no update. It’s still best practice to keep the pipeline intact.
However, if you don’t need J1 as upstream for J2/J3, you’ll need to remove the ‘build from other project’ for J2 in Jenkins and build could be polled from SCM automatically.