[build]: add branch and release name in sonic_version.yml (#6356)

the branch refers the branch name that the commit is in,
for example master, 202012, 201911, ...
In case there is no branch, the name will be HEAD.

release is encoded in /etc/sonic/sonic_release file.
the file is only available for a release branch.
It is not available in master branch.

example for master branch
```
build_version: 'master.602-6efc0a88'
debian_version: '10.7'
kernel_version: '4.19.0-9-2-amd64'
asic_type: vs
commit_id: '6efc0a88'
branch: 'master'
release: 'none'
build_date: Tue Dec 29 06:54:02 UTC 2020
build_number: 602
built_by: johnar@jenkins-worker-23
```

example for 202012 release branch
```
build_version: '202012.602-6efc0a88'
debian_version: '10.7'
kernel_version: '4.19.0-9-2-amd64'
asic_type: vs
commit_id: '6efc0a88'
branch: '202012'
release: '202012'
build_date: Tue Dec 29 06:54:02 UTC 2020
build_number: 602
built_by: johnar@jenkins-worker-23
```

Signed-off-by: Guohan Lu <lguohan@gmail.com>
This commit is contained in:
lguohan 2021-08-08 20:44:02 -07:00 committed by GitHub
parent 9c294586b7
commit cf73e22d52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 0 deletions

View File

@ -472,11 +472,16 @@ fi
## Version file ## Version file
sudo mkdir -p $FILESYSTEM_ROOT/etc/sonic sudo mkdir -p $FILESYSTEM_ROOT/etc/sonic
if [ -f files/image_config/sonic_release ]; then
sudo cp files/image_config/sonic_release $FILESYSTEM_ROOT/etc/sonic/
fi
export build_version="${SONIC_IMAGE_VERSION}" export build_version="${SONIC_IMAGE_VERSION}"
export debian_version="$(cat $FILESYSTEM_ROOT/etc/debian_version)" export debian_version="$(cat $FILESYSTEM_ROOT/etc/debian_version)"
export kernel_version="${kversion}" export kernel_version="${kversion}"
export asic_type="${sonic_asic_platform}" export asic_type="${sonic_asic_platform}"
export commit_id="$(git rev-parse --short HEAD)" export commit_id="$(git rev-parse --short HEAD)"
export branch="$(git rev-parse --abbrev-ref HEAD)"
export release="$(if [ -f $FILESYSTEM_ROOT/etc/sonic/sonic_release ]; then cat $FILESYSTEM_ROOT/etc/sonic/sonic_release; fi)"
export build_date="$(date -u)" export build_date="$(date -u)"
export build_number="${BUILD_NUMBER:-0}" export build_number="${BUILD_NUMBER:-0}"
export built_by="$USER@$BUILD_HOSTNAME" export built_by="$USER@$BUILD_HOSTNAME"

View File

@ -8,6 +8,12 @@ kernel_version: '{{ kernel_version }}'
{% endif -%} {% endif -%}
asic_type: {{ asic_type }} asic_type: {{ asic_type }}
commit_id: '{{ commit_id }}' commit_id: '{{ commit_id }}'
branch: '{{ branch }}'
{% if release is defined and release != '' -%}
release: '{{ release }}'
{% else -%}
release: 'none'
{% endif -%}
build_date: {{ build_date }} build_date: {{ build_date }}
build_number: {{ build_number }} build_number: {{ build_number }}
built_by: {{ built_by }} built_by: {{ built_by }}

View File

@ -1,6 +1,7 @@
export build_version="${sonic_version}" export build_version="${sonic_version}"
export asic_type="${sonic_asic_platform}" export asic_type="${sonic_asic_platform}"
export commit_id="$(git rev-parse --short HEAD)" export commit_id="$(git rev-parse --short HEAD)"
export branch="$(git rev-parse --abbrev-ref HEAD)"
export build_date="$(date -u)" export build_date="$(date -u)"
export build_number="${BUILD_NUMBER:-0}" export build_number="${BUILD_NUMBER:-0}"
export built_by="$USER@$BUILD_HOSTNAME" export built_by="$USER@$BUILD_HOSTNAME"