【问题标题】:How to pass the output of one ARM template to the input parameter of the next ARM template in Continuous Deployment using VSTS?如何在使用 VSTS 的持续部署中将一个 ARM 模板的输出传递给下一个 ARM 模板的输入参数?
【发布时间】:2018-04-10 17:32:08
【问题描述】:

我有一个 ServiceBuswithQueue ARM 模板,它的输出部分如下所示:

  "outputs": {
    "serviceBusNamespaceName": {
      "type": "string",
      "value": "[parameters('serviceBusNamespaceName')]"
    },
    "namespaceConnectionString": {
      "type": "string",
      "value": "[listkeys(variables('authRuleResourceId'), variables('sbVersion')).primaryConnectionString]"
    },
    "sharedAccessPolicyPrimaryKey": {
      "type": "string",
      "value": "[listkeys(variables('authRuleResourceId'), variables('sbVersion')).primaryKey]"
    },
    "serviceBusQueueName": {
      "type": "string",
      "value": "[parameters('serviceBusQueueName')]"
    }
  }

为此,我在 VSTS 中创建了持续集成 (CI) 和持续部署 (CD),在 CD 中,我使用 PowerShell 任务来部署上述 ARM 模板。但我想将这个 ARM 模板的输出(如“$(serviceBusQueueName)”)传递给持续部署中下一个 ARM 模板的输入参数。

知道上述场景可以在持续部署中的两个 ARM 任务之间使用 ARM 输出来实现。但我不想要它,因为目前我正在使用 PowerShell 任务来部署 ARM 模板。

在发布此问题之前,我进行了研究并找到了以下链接,但这些链接对解决我的问题没有帮助。

Azure ARM templates - using the output of other deployments

How do I use ARM 'outputs' values another release task?

谁能建议我如何解决上述问题?

【问题讨论】:

  • 您的意思是在 PowerShell 任务中一起部署 ARM 模板?
  • 是的 Starian,目前我正在使用 PowerShell 任务来部署 ARM 模板。
  • 可以直接使用输出吗?例如:$r=New-AzureRmResourceGroupDeployment ....,则可以在示例脚本中直接访问$r。
  • @starianchen-MSFT,实际上我的第一个 ARM 模板将输出为“serviceBusNamespaceName”。但我想将第一个 ARM 模板的输出用作下一个 ARM 模板的输入参数。
  • 您可以覆盖参数。

标签: arm azure-devops azure-resource-manager azure-pipelines-release-pipeline


【解决方案1】:

您可以通过指定相应的参数来覆盖参数。

Override template parameter in the script

【讨论】:

    【解决方案2】:
    # Start the deployment
    Write-Host "Starting deployment...";
    $outputs = New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -Mode Incremental -TemplateFile $templateFilePath -TemplateParameterFile $parametersFilePath;
    
    foreach ($key in $outputs.Outputs.Keys){
        $type = $outputs.Outputs.Item($key).Type
        $value = $outputs.Outputs.Item($key).Value
        Write-Host "##vso[task.setvariable variable=$key;]$value"
    }
    

    您可以在后续脚本中显示所有环境变量:

    Write-Host "Environment variables:"
    gci env:* | sort-object name
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-03
      • 1970-01-01
      • 2017-12-19
      相关资源
      最近更新 更多