diff --git a/lib/gitlab/backend/shell.rb b/lib/gitlab/backend/shell.rb
index d0060fbaca1e8159bbeb335f51917e8fe8fa687a..9cec71a32220a2632ea7b0f47332ba9a92db2b51 100644
--- a/lib/gitlab/backend/shell.rb
+++ b/lib/gitlab/backend/shell.rb
@@ -47,8 +47,8 @@ module Gitlab
 
         unless File.size?(secret_file)
           # Generate a new token of 16 random hexadecimal characters and store it in secret_file.
-          token = SecureRandom.hex(16)
-          File.write(secret_file, token)
+          @secret_token = SecureRandom.hex(16)
+          File.write(secret_file, @secret_token)
         end
 
         link_path = File.join(shell_path, '.gitlab_shell_secret')