Add dbt build task to vscode

posted on 2022-03-01

There is a plugin for vscode that allows you to run dbt code, but it is not available for the open source version of vscode.

Alternatively you can define a build task in vscode that allows you to quickly run DBT on your current SQL file.

In your dbt project, create a new file at .vscode/tasks.json with the contents:

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "label": "bdt_run",
      "type": "shell",
      "command": "dbt",
      "problemMatcher": [],
      "args": ["run", "-m", "${relativeFile}+"],
      "group": {
        "kind": "build",
        "isDefault": true
      }
    }
  ]
}

This will allow you to execute any SQL script in your dbt project, including sub dependencies, using ctrl+shift+b. Or use ctrl+shift+p to execute 'Tasks: Run Build Task'.