Merge branch 'sh-fix-environment-write-ref' into 'master'
Fix the writing of invalid environment refs
Closes #39182
See merge request gitlab-org/gitlab-ce!14993
(cherry picked from commit 3dcdd4a1)
3bff85a4 Fix the writing of invalid environment refs