Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
495 views
in Technique[技术] by (71.8m points)

tfs - VSTS: Pass build/release variables into Powershell script task

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

VSTS Build

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

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)}

Is there a way to pass all build variables into a script without having to explicitly specifying each one in a hash table?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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.

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.

More details are available here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...