diff --git a/contrib/automation/hgautomation/linux.py b/contrib/automation/hgautomation/linux.py
index d75142ef054a160dd4f7cc1c557e7c5343299c0d_Y29udHJpYi9hdXRvbWF0aW9uL2hnYXV0b21hdGlvbi9saW51eC5weQ==..198b51d453fea5fb02bb91360b279cf89477e88f_Y29udHJpYi9hdXRvbWF0aW9uL2hnYXV0b21hdGlvbi9saW51eC5weQ== 100644
--- a/contrib/automation/hgautomation/linux.py
+++ b/contrib/automation/hgautomation/linux.py
@@ -187,7 +187,7 @@
 
 sudo apt-key add docker-apt-key
 
-if [ "$DEBIAN_VERSION" = "9.8" ]; then
+if [ "$LSB_RELEASE" = "stretch" ]; then
 cat << EOF | sudo tee -a /etc/apt/sources.list
 # Need backports for clang-format-6.0
 deb http://deb.debian.org/debian stretch-backports main
@@ -271,7 +271,7 @@
     zip \
     zlib1g-dev"
 
-if [ "$DEBIAN_VERSION" = "9.8" ]; then
+if [ "LSB_RELEASE" = "stretch" ]; then
     PACKAGES="$PACKAGES linux-perf"
 elif [ "$DISTRO" = "Ubuntu" ]; then
     PACKAGES="$PACKAGES linux-tools-common"