'Environment variable not being passed down on VS Code in Windows -- bug or am I missing something?

I am doing development with https://github.com/google/clasp. clasp will use the environment variable clasp_config_auth. I have tested and confirmed that outside of VS Code if I set the environment variable clasp_config_auth then clasp picks it up and works as expected.

But in VS Code it does not work as expected.

I have the following in my tasks.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "options": {
        "env": {
            "clasp_config_auth": "~/path/to/file/.clasprc.json.me"
        }
    },
    "windows": {
        "options": {
            "env": {
                "clasp_config_auth": "%userprofile%\\path\\to\\file\\.clasprc.json",
            }
        }
    },
    "tasks": [
        {
            "label": "push to GAS",
            "type": "shell",
            "command": "clasp push",
            "group": {
                "kind": "build",
                "isDefault": true
            },
        }
    ]
}

Now, if I try to run the push to GAS task, I get this error:

> Executing task: clasp push <

ENOENT: no such file or directory, open 'C:\Users\me\Documents\work\project\%userprofile%\path\to\file\.clasprc.json'
The terminal process "C:\windows\System32\cmd.exe /d /c clasp push" terminated with exit code: 1.

C:\Users\me\Documents\work\project\ is the current working directory of my project.

It looks like VS Code is not setting the environment variable properly so clasp picks up C:\Users\me\Documents\work\project\%userprofile%\path\to\file\.clasprc.json instead of %userprofile%\path\to\file\.clasprc.json or C:\Users\me\path\to\file\.clasprc.json.

If I set the environment variable in a Command prompt and run clasp push it works as expected. But in VS Code it does not.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source