The Docker Hub documentation lists all these environment variables, which are available in your scripts in that environment:
SOURCE_BRANCH: the name of the branch or the tag that is currently being tested. SOURCE_COMMIT: the SHA1 hash of the commit being tested. COMMIT_MSG: the message from the commit being tested and built. DOCKER_REPO: the name of the Docker repository being built. DOCKERFILE_PATH: the dockerfile currently being built. DOCKER_TAG: the Docker repository tag being built. IMAGE_NAME: the name and tag of the Docker repository being built. (This variable is a combination of DOCKER_REPO:DOCKER_TAG.)
However, there are quite a few more, which might be useful in a certain environment; these were discovered by just printing the environment variables via a Perl script (which, BTW, you can use in Docker Hub for your own purposes).
SOURCE_TYPE: this one seems to contain
git. It might be different if it's pushed directly, or via the API.
PATH: is the regular system PATH. It contains
MAX_LOG_SIZE: it contains 67108864. Not clear if it can be changed.
BUILD_CODE: no idea what this is. It contains a code.
PUSH: it contains
trueif it's been created via PUSH. Probably other values if it's been automatically launched.
GIT_SHA1: no idea what the first one is, the second is the commit SHA1.
HOSTNAME: the host it's using to build.
DOCKER_HOST: the socket the client is using to connect, same as in the local docker installation.
- There's something called
SIGNED_URLS, which holds Amazon urls. No idea what this is, or how it can be useful.
CACHE_TAG, the tag that's being built, like
PYTHONUNBUFFEREDis equal to 1.
SOURCE_REPOSITORY_URLthe repository it's being built from.
LOG_BUILD_STEPSis set to
DOCKER_CFGcontains information on the user, including user tokens.
Out of all these, you can probably use
PUSH or even
GIT_SHA1 to introspect what's being built, and maybe take some actions. For instance, along with information on the last build you could create a script that built only those Dockerfiles that have changed.