How to run several tasks as a group?
Asked Answered
B

1

7

I created two tasks to assist me in the development of a web site:

{
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "build site",
            "command": "jekyll b --watch --incremental",
            "type": "shell",
            "group": "build"
        },
        {
            "taskName": "serve site",
            "command": "./_devd -ol _site",
            "type": "shell",
            "group": "build"
        }
    ]
}

I can start them one by one with F1 → Run Task (so I need to issue the sequence twice, once for each task) and I end up with two tasks running at the same time.

Is it possible to automate this and run a group of tasks at the same time? I thought that the group entry would, well, group them together but it is not the case (they are just recognized as belonging to the build or test group - and I did not find a way to start the whole group at once).

Beside answered 3/8, 2017 at 13:49 Comment(0)
M
13

You can use the "dependsOn" attribute. If you want to run the "build site" task first, add it as the "dependsOn" of the "serve site" task. If you want both to run together, make another task that depends on both the "build site" and "serve site" tasks.

Here is an example of building the site before serving it:

{
  "taskName": "build site",
  "command": "jekyll b --watch --incremental",
  "type": "shell",
  "group": "build"
},
{
  "taskName": "serve site",
  "command": "./_devd -ol _site",
  "type": "shell",
  "group": "build",
  "dependsOn": "build site" // <--- Added this
},

Not aware of a cleaner way to do this with long running tasks but...

Here is an example of running both tasks at the same time:

{
  "taskName": "Run Everything", // <-- Bind this task to a key
  "dependsOn": [ "build site", "serve site" ]
},
{
  "taskName": "build site",
  "command": "jekyll b --watch --incremental",
  "type": "shell"
},
{
  "taskName": "serve site",
  "command": "./_devd -ol _site",
  "type": "shell"
}

Update: Here's a link to the documentation for the new tasks.json template (v2.0.0). The portion relevant to this question is that taskName has been renamed to label, but dependsOn's value remains the same.

Municipalize answered 3/8, 2017 at 14:22 Comment(2)
Thanks, but this will not work because "build site" is a task which does not end. Both tasks do not end, actually, and must be ran in parallel.Beside
May want to look into vscode's background option for tasks. I've not used it, so I do not know the limitations. code.visualstudio.com/docs/editor/…Municipalize

© 2022 - 2024 — McMap. All rights reserved.