本文介绍如何使用 mainTemplate.json 文件中的 _artifactsLocation
和 _artifactsLocationSasToken
参数引用 Azure 应用程序产品/服务中的 链接项目。 通过合作伙伴中心或服务目录发布的解决方案模板和托管应用程序产品/服务现在必须使用这些参数来引用产品/服务包中的链接项目。 工件是您在产品/服务包中除 mainTemplate.json 和 createUIDefinition.json 文件外包含的任何其他文件,包括脚本和嵌套模板。
如何使用项目位置参数
让我们定义相关参数:
_artifactsLocation
:将暂存部署的所有项目的基 URI。 在为参数提供值时,`defaultValue` 必须包含尾部斜杠。
_artifactsLocationSasToken
:访问参数中指定的 _artifactsLocation
位置所需的 SAS 令牌。 defaultValue 应为空字符串“”。 当模板与其随附的项目一起部署时,系统会自动为其生成 SAS 令牌。
以下示例展示了在_artifactsLocation
文件中用于_artifactsLocationSasToken
和参数的示例参数配置:
{
"parameters": {
"_artifactsLocation": {
"type": "string",
"metadata": {
"description": "Base URI where all artifacts for the deployment will be staged. The defaultValue must include a trailing slash when providing a value for the parameter."
},
"defaultValue": "[deployment().properties.templateLink.uri]"
},
"_artifactsLocationSasToken": {
"type": "securestring",
"metadata": {
"description": "SAS token required to access the location specified in the ```_artifactsLocation``` parameter. The defaultValue should be an empty string "". When the template is deployed with its accompanying artifacts, a SAS token will be automatically generated for them."
},
"defaultValue": ""
}
}
}
将项目参数添加到 mainTemplate.json 文件后,可以为项目构造 URI 变量。 必须使用 uri() 函数创建这些变量。 *** 添加 uri 函数文档的链接***
以下示例显示了脚本的示例配置和将在 mainTemplate.json 文件中定义的嵌套模板项目:
{
"variables": {
"scriptFileUri": "[uri(parameters('_artifactsLocation'), concat('scripts/configuration.sh', parameters('_artifactsLocationSasToken')))]",
"nestedTemplateUri": "[uri(parameters('_artifactsLocation'), concat('nestedtemplates/jumpbox.json', parameters('_artifactsLocationSasToken')))]"
}
}
这些参数在部署期间的工作原理
在部署期间,Azure 应用程序服务将使用 SAS 令牌更新 _artifactsLocationSasToken
参数的值,该令牌提供对产品/服务中提供的项目的访问权限。 这可确保在客户部署期间可以访问文件。 它还允许服务仅在部署期间提供对项目的访问权限,而无需不断向 Internet 提供这些文件。
后续步骤
若要详细了解 Azure 应用程序中的项目位置验证,请参阅 ARM 模板的测试用例。