Reference git commit hash in the docker hub automated build Docker Tag field

Is it possible to reference a subset of the characters in the git commit hash in the Docker Tag of the docker hub automated build process (referring to the page at https://hub.docker.com/repository/docker/$USERNAME/$REPOSITORY_NAME/builds/edit)? I have been manually tagging images for a container I maintain with, for example 0.1-1d50ea4 where 1d50ea4 derives from the first seven characters of the git commit hash from which the container image was built.

I reviewed the documentation on docker hub automated builds but was not able to find a complete listing of the variables available in the “Docker Tag” field in the “Build Rules” section of the “Build configurations” page for my repository. The examples include {sourceref}, which appears to refer to the git tag but I am wondering if there is a {commitref} or something of that nature.

If all of the environment variables listed on the Advanced options for Autobuild and Autotest#environment-variables-for-building-and-testing were available in the docker hub Docker Tag field then perhaps something to do with {SOURCE_COMMIT} would work, if there were a way to select a subset of that string there. However, I don’t know if those environment variables are available in that context, and if so, how to manipulate them.

Hello,

Sounds there no built-in feature for that but you can use post_push for that.
Create an executable post_push in a hooks directory in the same directory than your Dockerfile with the following content

#!/bin/bash

docker tag $IMAGE_NAME $DOCKER_REPO:$SOURCE_COMMIT
docker push $DOCKER_REPO:$SOURCE_COMMIT