在tasks.json中重用环境变量

问题描述 投票:0回答:1

这是我的tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "login",
            "type": "shell",
            "command": "go run main.go login",
            "options": {
                "env": {
                    "dbConnectionString": "host=localhost port=5431 user=user dbname=db password=pass sslmode=disable",
                    "spotifyClientID": "some-value",
                    "spotifyClientSecret": "another-value"
                }
            },
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "getPlaylists",
            "type": "shell",
            "command": "go run main.go getPlaylists",
            "options": {
                "env": {
                    "dbConnectionString": "host=localhost port=5431 user=user dbname=db password=pass sslmode=disable",
                    "spotifyClientID": "some-value",
                    "spotifyClientSecret": "another-value"
                }
            },
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

我不想在每个任务中复制粘贴相同的环境变量。可能有一种方法可以在一个地方定义所有环境变量,然后在每个任务中重复使用它们?

visual-studio-code
1个回答
0
投票

这个配置对我有用:

{ "version": "2.0.0",
  "options":{
    "env":{}
  },
  "tasks": [ ]
}
© www.soinside.com 2019 - 2024. All rights reserved.