8.2.3. Git Branch and Commit Hash¶
8.2.3.1. Background¶
You are using Git and want to automatically reflect the current branch and current commit hash in order to use it within the configuration.
8.2.3.2. What can be configured?¶
You can use Git commands and parse their one-line output into an environment variable which can then be referenced inside the Axivion configuration.
8.2.3.3. What needs to be done?¶
For reflecting the current branch you can use code like the following in your
analysis start batch file in order to set the environment variable
AXIVION_BRANCH_NAME and then use that variable e.g. within the configured
/Project/name and also as /Project/VCSIntegration/Git/branch:
for /F "tokens=* usebackq" %%F in (`git rev-parse --abbrev-ref HEAD`) do (
set "AXIVION_BRANCH_NAME=%%F"
)
export AXIVION_BRANCH_NAME="$(git rev-parse --abbrev-ref HEAD)"
For reflecting the current commit hash you can use the following code to set the
environment variable AXIVION_VERSION_NAME (which is default) in order to
import the commit hash next to the timestamp into the project database:
for /F "tokens=* usebackq" %%F in (`git rev-parse HEAD`) do (
set "AXIVION_VERSION_NAME=%%F"
)
export AXIVION_VERSION_NAME="$(git rev-parse HEAD)"
In a “Local Build” scenario you can set the reference version as follows:
git fetch %REMOTE%
for /F "tokens=* usebackq" %%F in (`git merge-base %REMOTE%/%BRANCH% HEAD`) do (
set "AXIVION_VERSION_NAME_FILTER=* (%%F)"
)
git fetch $REMOTE
export AXIVION_VERSION_NAME_FILTER="* ($(git merge-base $REMOTE/$BRANCH HEAD))"
Where you have to substitute %REMOTE% and %BRANCH% on Windows (or
$REMOTE and $BRANCH on GNU/Linux or macOS) with the appropriate remote
and branch names respectively for the branch you created the current branch from.