We have a huge ~20GB monorepo. For a particular Jenkins job, we do not need to clone the entire repo but only need a few sub-directories. The solution for this is of course git sparse checkout. However this is quiet cumbersome to set up and maintain. You probably have to run the job a few times to make sure you did not miss any directory. Also, in the future if you added a dependency (inside another directory) that was not in the sparse checkout list, you have to remember to add it back.
What if we can improve this process?
- We should be able to identify all the scripts that a particular Jenkins job needs by looking into all the files that the OS has opened inside that job's working directory.
- We already have tools like
lsof
,sysdig
,opensnoop
which can show us all files that are open inside a directory. - On the first ever run of the Jenkins job, we clone the entire repo.
- Then we start
lsof +D /job/workspace
and monitor which files got opened. - At the end of the job we create a data structure like
{JOB_NAME: [list, of, files]}
and save it somewhere. - Rerun the job ~5 times to ensure data correctness.
- On all subsequent runs, the git clone command will parse above file and only
sparse-checkout
the required files. - If in the future, the job fails due to a
FileNotFound
error, we can infer that a new dependency was added, add that new dependency and re-run the job.
Wanted to run the viability of this idea with the DevOps Community.