VSTS:将构建/发布变量传递到Powershell脚本任务中 [英] VSTS: Pass build/release variables into Powershell script task

查看:60
本文介绍了VSTS:将构建/发布变量传递到Powershell脚本任务中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

理想情况下,我想使用构建变量(在VSTS上)配置Azure Web App应用程序设置,例如:

Ideally, I would want to configure our Azure Web App application settings using build variables (on VSTS), for example:

我们使用Powershell脚本执行发布任务.为了设置应用程序设置,可以使用以下脚本:

We perform our publish tasks using Powershell scripts. In order to set app settings, the following script could be used:

param($websiteName, $appSettings)
Set-AzureWebsite -Name $websiteName -AppSettings $appSettings

我可以将这些构建变量手动传递到Powershell脚本构建任务中,如下所示:

I could pass these build variables manually into a Powershell script build task, like so:

PrepareAppSettings.ps1 -websiteName "MyWebApp" -appsettings @{"MyConnectionString" = $(MyConnectionString);"MyRandomService" = $(MyRandomService);"MyRandomServiceClient"=$(MyRandomServiceClient);"MyRandomServicePassword"=$(MyRandomServicePassword)}

是否有一种方法可以将所有构建变量传递到脚本中,而不必在哈希表中明确指定每个构建变量?

推荐答案

构建变量将作为环境变量自动传递给所有PowerShell脚本.

Build Variables are automatically passed to all the PowerShell scripts as environment variables.

因此,如果您在Variables部分中定义了变量myVar.您可以在脚本中以$env:myVar的身份对其进行访问.这里要注意的一件事是.转换为_.例如.如果变量为myVar.config,则将在脚本中以$env:myVar_config的身份访问它.

So if you have defined a variable myVar in the Variables section. You can access it as $env:myVar in your script. One thing to note here is that . is converted to a _. For eg. if your variable is myVar.config, you will access it in your script as $env:myVar_config.

可用变量还包括变量,例如分支名称,内部版本号等.要查看所有可用变量,请运行虚拟的构建/发行版定义并添加具有内联类型的PowerShell任务,然后运行Get-ChildItem Env:.这将向您显示所有可用的环境变量,并且您可以看到所有自定义定义的变量.

The available variables also include variables such as branch name, build number etc. To see all the available variables, run a dummy build/release definition and add a PowerShell task with inline type and run Get-ChildItem Env:. This will show you all the available environment variables and you can see all your custom defined variables.

可在此处

这篇关于VSTS:将构建/发布变量传递到Powershell脚本任务中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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