Git Commit Hash
The Git Commit Hash recipe creates a short version of the current Git commit hash and provides it as an environment variable. In the default configuration, the value is available in subsequent build steps as %env.GIT_COMMIT_SHORT_HASH%.
| Recipe ID | jjideenschmiede/git-commit-hash |
| Marketplace | Git Commit Hash |
| Source code | GitHub |
How It Works
The recipe reads the VCS revision of the build from the environment variable BUILD_VCS_NUMBER, shortens it to the configured length and sets the result as a build parameter. Neither access to the repository nor an installed Git on the agent is required.
Installation
The recipe requires TeamCity 2025.03 or later. How to add it to a build configuration is described under Using a Recipe.
Inputs
| Input | Required | Default | Description |
|---|---|---|---|
| Hash Length | No | 7 | Number of characters for the short commit hash (between 4 and 40) |
| Environment Variable Name | No | GIT_COMMIT_SHORT_HASH | Name of the environment variable that stores the short hash |
Output
| Parameter | Description | Example |
|---|---|---|
env.GIT_COMMIT_SHORT_HASH | Short commit hash; the name follows the input Environment Variable Name | a1b2c3d |
Example
Usage in a subsequent command line step, for example as a tag for a Docker image:
docker build -t registry.example.com/app:%env.GIT_COMMIT_SHORT_HASH% .
Notes
- The recipe does not validate the range of Hash Length. If the value is larger than the length of the hash, the complete hash is used; a value that is not a number leads to an error.
- The build needs a VCS root. Without a VCS revision, the recipe fails with an error.
- For builds with several VCS roots, TeamCity provides the revision per root in separate variables. The recipe only uses
BUILD_VCS_NUMBER.