使用工件开关创建 Azure VM

Create Azure VM with artifact switch

我正在尝试通过 CLI 创建虚拟机,并在开发测试实验室中添加来自 public 存储库的工件。

这是我的脚本: az lab vm create --resource-group TestRG --lab-name TestLab --name 'ScriptVM' --image "Windows 10 Pro, Version 1809" --image-type gallery --size 'Standard_B2s' --admin-username 'user' --admin-password 'pw' --artifacts '{ "/artifactsources/publicrepo/artifacts/linux-java" }'

我不知道工件开关的格式,因为它只是说一个 JSON 编码数组。这是如何运作的?我只是得到错误 Expecting property name enclosed in double quotes: line 1 column 3 (char 2)

以下示例显示了构成定义文件基本结构的部分:

{
  "$schema": "https://raw.githubusercontent.com/Azure/azure-devtestlab/master/schemas/2016-11-28/dtlArtifacts.json",
  "title": "",
  "description": "",
  "iconUri": "",
  "targetOsType": "",
  "parameters": {
    "<parameterName>": {
      "type": "",
      "displayName": "",
      "description": ""
    }
  },
  "runCommand": {
    "commandToExecute": ""
  }
}

它位于您的 Git 存储库 中,并在 AZ 命令中被引用。整个过程的视频可以在我们的文档中找到。

https://docs.microsoft.com/en-us/azure/lab-services/devtest-lab-artifact-author

所以答案是 JSON 中没有所有必需的元素。我还犯了在 PS 脚本中转义引号的错误。最后的切换最终看起来像这样:--artifacts '[{"""artifactId""": """artifacts/windows-notepadplusplus"""}]'