Is it possible to group tasks and specify global options for the group in VS Code?

Viewed 22

I am doing development that gets pushed/built to multiple systems. To push/build to each system, I am using the same command but have to change an environment variable.

I am using tasks.json to push to multiple systems with one task and I am using task options to set the environment variable.

As you can see it, it is kinda messy.

{
    "version": "2.0.0",

    // global options
    "options": {
        "env": {
            "SOME_ENV_VAR": "~/globalFile"
        }
    },
    // global options for windows
    "windows": {
        "options": {
            "env": {
                "SOME_ENV_VAR": "${env:userprofile}\\globalFile",
            }
        }
    },
    "tasks": [
        {
            "label": "push to system A",
            "type": "shell",
            "command": "pushCommand"
        },
        {
            "label": "push to system B",
            "type": "shell",
            "command": "pushCommand",
            // special options for pushing to sytem B
            "options": {
                "env": {
                    "SOME_ENV_VAR": "~/systemBFile"
                }
            },
            // special windows options for pushing to system B
            "windows": {
                "options": {
                    "env": {
                        "SOME_ENV_VAR": "${env:userprofile}\\systemBFile",
                    }
                }
            }
        },
        // main task to run both 
        {
            "label": "push",
            "type": "shell",
            "dependsOrder": "parallel",
            "dependsOn": [
                "push to system A",
                "push to system B"
            ]
        },

        {
            "label": "build to system A",
            "type": "shell",
            "command": "buildCommand"
        },
        {
            "label": "build to system B",
            "type": "shell",
            "command": "buildCommand",
            // special options for pushing to sytem B
            "options": {
                "env": {
                    "SOME_ENV_VAR": "~/systemBFile"
                }
            },
            // special windows options for pushing to system B
            "windows": {
                "options": {
                    "env": {
                        "SOME_ENV_VAR": "${env:userprofile}\\systemBFile",
                    }
                }
            }
        },
        // main task to run both 
        {
            "label": "build",
            "type": "shell",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "dependsOrder": "parallel",
            "dependsOn": [
                "build to system A",
                "build to system B"
            ]
        }
    ]
}

So I am wondering if I can create different groups, one for each system: system A, system B, system C, etc... and then assign options and windows to those groups to make it easier to manage. Something like this:

{
    "label": "build to system A",
    "type": "shell",
    "command": "buildCommand",
    "group": "system A"
},
{
    "label": "build to system B",
    "type": "shell",
    "command": "buildCommand",
    "group": "system B"
}
0 Answers
Related