参数和变量如何传递给任务
如何查找参数名称和值
您应该在其中找到任务“task.json”文件。它位于其源目录中(您也可以解压任务的 .vsix 文件)。由于 Azure DevOps(由 Microsoft 开发)的所有默认任务都是 available on Github,因此很容易做到。
示例
让我们更改“.NET Core”任务的参数“Command”的值。它的“task.json”文件是here。在“输入”部分查找“命令”文本:
"inputs": [
{
"name": "command",
"type": "pickList",
"label": "Command",
"defaultValue": "build",
"required": true,
"helpMarkDown": "The dotnet command to run. Select 'Custom' to add arguments or use a command not listed here.",
"options": {
"build": "build",
"push": "nuget push",
"pack": "pack",
"publish": "publish",
"restore": "restore",
"run": "run",
"test": "test",
"custom": "custom"
},
"properties": {
"EditableOptions": "False"
}
},
您可以看到参数名称与其标签相同(并非总是如此),并且值为“build”,“push”,“pack”,...
现在您可以在对构建进行排队时添加一个名为input_command(不区分大小写)的变量,并在那里填写值。这将覆盖您在管道定义中设置的任何内容。
无论参数的类型是什么,参数的值都以字符串的形式发送。例如,布尔参数的值可能是“true”或“false”,而选择列表参数对于选择列表中的每个项目都有一个对应的字符串值(如上例)。
再举一个例子,让我们看看“NuGet 还原”任务。它在“高级”部分中有一个“详细程度”参数。打开task.json 文件。以下是相关部分:
{
"name": "verbosityRestore",
"type": "pickList",
"label": "Verbosity",
"defaultValue": "Detailed",
"helpMarkDown": "Specifies the amount of detail displayed in the output.",
"required": "false",
"groupName": "restoreAdvanced",
"options": {
"Quiet": "Quiet",
"Normal": "Normal",
"Detailed": "Detailed"
}
},
任务的每个“命令”的参数名称都不同。对于恢复命令,它是“verbosityRestore”。