Running CircleCI jobs based on file diffs

Hi folks

We’re discussing creating different Docker images (microservices) from the same Bitbucket code repository. Each service will have its own folder and Dockerfile.

What’s the best way to handle this in a CircleCI workflow? I can write some Bash to git diff the files and only build affected Docker images, but this means with ~10 services we’d have 9 jobs simply echo’ing “No files diff’d, skipping”. It would also mean we’d end up using “credits” for each of these jobs, with no useful output.

Is there a cleaner way to do this, e.g. having jobs only run if certain files have been changed? I know Gitlab can do this pretty easily.

Thanks in advance
Duncan

:wave:

It sounds like you are using a monorepo approach here. There is a lengthy discussion about monorepos at the thread linked below which may be beneficial for you.

Some of the information nearer the end of the thread will be more relevant as CircleCI has changed a bit since the thread initially started. In essence, you will need at least one job to check out the repo and see if any files have changed and then trigger appropriate workflows depending on which files have been changed. In particular, this linked article should help with some insight on how to achieve this:

I hope this helps point you in the right direction!