CI PowerShell variables do not resolve properly for cache keys

Summary

PowerShell CI variables e.g. $env:CI_BUILD_REF_NAME are not resolved properly for cache keys.

(Same issue with new variables as well e.g. CI_COMMIT_REF_NAME)

Steps to reproduce

  1. Use PowerShell as the shell executer
[[runners]]
  name = "windows-01"
  url = ""
  token = ""
  executor = "shell"
  shell = "powershell"
  1. Set global cache using $env:CI_BUILD_REF_NAME as cache key
cache:
         key: "$env:CI_BUILD_REF_NAME"
         untracked: true
  1. Run build

Actual behavior

  1. Extracting cache
Checking cache for :CI_BUILD_REF_NAME...
FATAL: open ..\..\..\..\..\cache\engine\electron\:CI_BUILD_REF_NAME\cache.zip: The filename, directory name, or volume label syntax is incorrect. 
Failed to extract cache
  1. Writing cache
WARNING: GetFileAttributesEx ..\..\..\..\..\cache\engine\electron\:CI_BUILD_REF_NAME\cache.zip: The filename, directory name, or volume label syntax is incorrect. 
FATAL: open ..\..\..\..\..\cache\engine\electron\:CI_BUILD_REF_NAME\archive_025139343: The filename, directory name, or volume label syntax is incorrect. 
Failed to create cache

Expected behavior

  1. Extracting cache
Checking cache for master...
Successfully extracted cache
  1. Writing cache
Creating cache master...
...    
Created cache
Job succeeded

Relevant logs and/or screenshots

Added in sections above

Environment description

  1. Custom Gitlab installation
  2. gitlab-runner on Microsoft Windows Server 2016 Standard

Used GitLab Runner version

Version:      9.5.0
Git revision: 413da38
Git branch:   9-5-stable
GO version:   go1.8.3
Built:        Tue, 22 Aug 2017 13:40:42 +0000
OS/Arch:      windows/amd64