# Running CircleCI jobs based on file diffs

**URL:** <https://discuss.circleci.com/t/running-circleci-jobs-based-on-file-diffs/38079>\
**Category:** Build Environment\
**Created:** [November 10, 2020, 3:24pm UTC](https://discuss.circleci.com/t/running-circleci-jobs-based-on-file-diffs/38079 "2020-11-10T15:24:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![duncanwraight](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@duncanwraight](https://discuss.circleci.com/u/duncanwraight)\
**Post date:** [November 10, 2020, 3:24pm UTC](https://discuss.circleci.com/t/running-circleci-jobs-based-on-file-diffs/38079/1 "2020-11-10T15:24:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bytesguy](https://avatars.discourse-cdn.com/v4/letter/b/0ea827/32.png) [@bytesguy](https://discuss.circleci.com/u/bytesguy)\
**Post date:** [November 11, 2020, 11:18am UTC](https://discuss.circleci.com/t/running-circleci-jobs-based-on-file-diffs/38079/2 "2020-11-11T11:18:05Z")

</div>

👋

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.

[https://discuss.circleci.com/t/does-circleci-2-0-work-with-monorepos/10378/32](https://discuss.circleci.com/t/does-circleci-2-0-work-with-monorepos/10378/32)

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:

> **[Monorepo with CircleCI Conditional Workflows](https://medium.com/labs42/monorepo-with-circleci-conditional-workflows-69e65d3f1bd0)**
>
> Monorepos bring simplicity to the development process, but raise the complexity of automated builds and deploy.

I hope this helps point you in the right direction!
