It seems you want some sort of conditional functionality in your build pipeline. You might find Make to be quite useful for this.
Under the hood, Make is a simple rule-based script engine. One of the main highlights of Make is the ease with which you’re able to instruct it to do something when a file changes.
For example, take a look at one of the Makefiles I have for a project:
OUT := bin/www
# Collect any file dependencies
FILES := $(shell find src -name "*")
$(OUT): Makefile $(FILES)
The Makefile declares the bin/www folder as the final target of the build script and assigns it at least one dependency: the Makefile itself. The
FILES variable, when expanded, resolves to whatever files are found in the src directory; these files are then treated as dependencies themselves. If any one of the dependencies change (compared to the last successful build), Make will run the indented line—which itself executes another the main build script.