# How to skip jobs based on the files changed in a subdirectory?

**URL:** <https://travis-ci.community/t/how-to-skip-jobs-based-on-the-files-changed-in-a-subdirectory/2979>\
**Category:** Feature Requests\
**Created:** [April 10, 2019, 8:23pm UTC](https://travis-ci.community/t/how-to-skip-jobs-based-on-the-files-changed-in-a-subdirectory/2979 "2019-04-10T20:23:06Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![dwjbosman](https://avatars.discourse-cdn.com/v4/letter/d/3ec8ea/32.png) [@dwjbosman](https://travis-ci.community/u/dwjbosman)\
**Post date:** [September 18, 2019, 8:01am UTC](https://travis-ci.community/t/how-to-skip-jobs-based-on-the-files-changed-in-a-subdirectory/2979/12 "2019-09-18T08:01:28Z")

</div>

Another script:

```
#!/bin/bash
set -e
# This script is called by Travis during the install step.
# It returns 1 if no files where changed. In that case
# no further building/test is required for this image

IMAGE_NAME=$1

echo "Travis event type: $TRAVIS_EVENT_TYPE"

if ["$TRAVIS_EVENT_TYPE" == "api"]
then
    # trigger via travis dashboard
    # test all
    echo "Trigger all tests"
    exit 0
fi

# in our repo each job runs in it's own folder
cd "$IMAGE_NAME-docker"

CHANGED_FILES=$(git diff --name-status HEAD~1...HEAD .)
if [-z "$CHANGED_FILES"]
then
    # nothing changed, skip building
    echo "No changes in $IMAGE_NAME, terminate"
   
    # this indicates to the parent script that the build can be terminated
    exit 137
fi

echo "There were changes in $IMAGE_NAME changes: $CHANGED_FILES"
exit 0

```

In the travis.yml file the script is called during the install phase

`./check_changed.sh $IMAGE_NAME ; RETURN_CODE=$? ; if [$RETURN_CODE -eq 137]; then travis_terminate 0; elif [$RETURN_CODE -ne 0]; then travis_terminate $RETURN_CODE; fi`

If the check\_changes script fails somehow you want to detect this and fail the build with an error.

---

_[View the full topic](https://travis-ci.community/t/how-to-skip-jobs-based-on-the-files-changed-in-a-subdirectory/2979)._
