[build] When generating image version, handle case where current commit has no reachable tags (#2506)

Signed-off-by: Joe LeVeque <jolevequ@microsoft.com>
This commit is contained in:
Joe LeVeque 2019-01-31 14:48:48 -08:00 committed by lguohan
parent 3f138e899c
commit d426584748

View File

@ -60,7 +60,7 @@ sonic_get_version() {
BUILD_NUMBER=${BUILD_NUMBER:-0}
## Check if we are on tagged commit
## Note: escape the version string by sed: / -> _
if [ "$describe" == "$latest_tag" ]; then
if [ -n "$latest_tag" ] && [ "$describe" == "$latest_tag" ]; then
echo "${latest_tag}${dirty}" | sed 's/\//_/g'
else
echo "${branch_name}.${BUILD_NUMBER}${dirty:--$(git rev-parse --short HEAD)}" | sed 's/\//_/g'