如何在另一个发布任务中使用ARM“输出"值? [英] How do I use ARM 'outputs' values another release task?

查看:82
本文介绍了如何在另一个发布任务中使用ARM“输出"值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an ARM template that has and outputs section like the following:

"outputs": {
    "sqlServerFqdn": {
        "type": "string",
        "value": "[reference(concat('Microsoft.Sql/servers/', variables('sqlserverName'))).fullyQualifiedDomainName]"
    },
    "primaryConnectionString": {
        "type": "string",
        "value": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('sqlserverName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('databaseName'), ';User Id=', parameters('administratorLogin'), '@', variables('sqlserverName'), ';Password=', parameters('administratorLoginPassword'), ';')]"
    },
    "envResourceGroup": {
        "type": "string",
        "value": "[parameters('hostingPlanName')]"
    }
}

我有一个使用模板的Azure资源组部署任务.然后,我想在下一个任务中使用变量$(sqlServerFqdn)进行配置.该变量似乎不仅在填充,而且我找不到任何地方可以告诉我如何在发布时使用输出"值.

I have a Azure Resource Group Deployment task that uses the template. I then want to use the variable $(sqlServerFqdn) in the next task for configuration. The variable doesn't seem to just populate and I cannot find anywhere that tells me how to use 'outputs' values on release.

在此ARM模板运行之后,我需要怎么做才能填充变量以用于配置任务?一个示例就是Powershell脚本任务或另一个ARM模板的参数.

What do I need to do to get the variable to populate for use in configuring tasks after this ARM template runs? An example would be in the parameters to a powershell script task or another ARM template.

推荐答案

捕获此答案,因为在寻找解决方案时,我总是会遇到这个问题.

Capturing this answer because I always end up at this question when searching for the solution.

有一个市场任务使ARM模板输出参数可用进一步的管道.但是在某些情况下,您无权购买用于订阅的市场项目,因此以下PowerShell将执行相同的操作.要使用它,您可以在ARM模板资源组部署步骤之后立即将其添加为powershell脚本步骤.它将查看最后的部署,并将输出变量提取到管道变量中.

There is a marketplace task which makes ARM template output parameters available further down the pipeline. But in some cases you don't have permission to purchase marketplace items for your subscription, so the following PowerShell will do the same thing. To use it you add it as a powershell script step immediately following the ARM template resource group deployment step. It will look at the last deployment and pull the output variables into pipeline variables.

param(
 [string]  $resourceGroupName
)

$lastDeployment = Get-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName | Sort Timestamp -Descending | Select -First 1 

if(!$lastDeployment) {
    throw "Deployment could not be found for Resource Group '$resourceGroupName'."
}

if(!$lastDeployment.Outputs) {
    throw "No output parameters could be found for the last deployment of Resource Group '$resourceGroupName'."
}

foreach ($key in $lastDeployment.Outputs.Keys){
    $type = $lastDeployment.Outputs.Item($key).Type
    $value = $lastDeployment.Outputs.Item($key).Value

    if ($type -eq "SecureString") {
        Write-Host "##vso[task.setvariable variable=$key;issecret=true]$value" 
    }
    else {
        Write-Host "##vso[task.setvariable variable=$key;]$value" 
    }
}

请注意,环境变量在此脚本的上下文中将不可用,但在后续任务中将可用.

Note that the environmental variables won't be available in the context of this script, but will in subsequent tasks.

这篇关于如何在另一个发布任务中使用ARM“输出"值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆