Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment variables not persisted across task chains #38793

Closed
IAmHopp opened this issue Nov 20, 2017 · 0 comments
Closed

Environment variables not persisted across task chains #38793

IAmHopp opened this issue Nov 20, 2017 · 0 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug tasks Task system issues verified Verification succeeded
Milestone

Comments

@IAmHopp
Copy link

IAmHopp commented Nov 20, 2017

  • VSCode Version: Code 1.18.1 (929bacb, 2017-11-16T18:32:36.023Z)
  • OS Version: Windows_NT x64 6.3.9600
  • Extensions:
Extension Author (truncated) Version
java red 0.14.0
vscode-java-debug vsc 0.3.1
vscode-java-pack vsc 0.2.0

Hi, guys. First issue here. What I'll describe is a task/terminal issue. I looked around the related repositories, but still think it fits here. Let me know if I'm wrong.

I'm using dependsOn to create a chain of tasks that run synchronously depending on the completion of the previous one. I have about five in a chain in a project I'm working on. To simplify task commands, I've removed some common information to environment variables and I'm referencing those using the $env:variable syntax.

This works, but only for the first task. To clarify, the first task is usually not the one I'm executing. Through a chain of dependsOn, the one I'm executing is actually the last one to be executed. But all tasks besides the first one fail, because the environment variables aren't being carried through.

To be clear, I'm not setting these variables per task. I'm setting them on the root of the tasks.json file. I'm using PowerShell for the integrated terminal, if that makes any difference.


Steps to Reproduce:

  1. Create a tasks.json file with this minimal markup:
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "options":
    {
        "env":
        {
            "Variable": "Issue with environment variables."
        }
    },
    "tasks":
    [
        {
            "command": "Write-Host Variable: $env:Variable",
            "dependsOn": "First task",
            "label": "Main task",
            "problemMatcher": [],
            "type": "shell"
        },
        {
            "command": "Write-Host Variable: $env:Variable",
            "label": "First task",
            "problemMatcher": [],
            "type": "shell"
        }
    ]
}

Notice how the variable is set for the whole file, not for any individual task. Also notice how I'm not overriding options in any of the individual ones.

  1. Run the Main task.

This is the output I'm getting:

Executing task: Write-Host Variable: $env:Variable <

Variable: Issue with environment variables.

Terminal will be reused by tasks, press any key to close it.

Executing task: Write-Host Variable: $env:Variable <

Variable

Obviously, I wanted the variable to show up in both tasks.

Alright, that's it. Hope that was clear enough. Loving using the tool!

Reproduces without extensions: Yes

@vscodebot vscodebot bot added the tasks Task system issues label Nov 20, 2017
@dbaeumer dbaeumer added bug Issue identified by VS Code Team member as probable bug and removed new release labels Nov 21, 2017
@dbaeumer dbaeumer added this to the November 2017 milestone Nov 21, 2017
@mjbvz mjbvz added the verified Verification succeeded label Dec 6, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug tasks Task system issues verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

3 participants