VSTS将变量传递到Azure PowerShell脚本参数中 [英] VSTS passing variables into Azure PowerShell Script Arguments
问题描述
我有多个Azure PowerShell任务,我想在其中传递变量.目前,我正在使用脚本参数传递变量,如屏幕截图所示:
I have multiple Azure PowerShell tasks in which I'd like to pass variables. Currently I'm passing variables with Script Arguments, like on the screenshot:
脚本参数的问题在于,如果有更改,我必须在每个过程中都对其进行编辑.是否只有一个变量可以链接到多个进程? 我看过 VSTS:将构建变量传递到Powershell脚本任务中一个>,但是无论我如何编辑脚本,它们都无法工作.该主题也没有解释是否应将变量放入流程变量或队列构建变量"中. 这是我要自动执行的脚本:
The problem with Script Arguments is that I'd have to edit them in every process if there is a change. Is it possible to have just a single variable that I can link to multiple processes? I've looked at VSTS: Pass build variables into Powershell script task but no matter how I edit my scripts they refuse to work. That topic also doesn't explain if variables should be put into process variables or Queue Build Variables. Here is the script that I'm trying to automate:
param
(
[Parameter(Mandatory)]
[String]$NewFileLocation1
)
Set-AzureRmVMCustomScriptExtension -Argument "-NewFileLocation1 $NewFileLocation" -ResourceGroupName Test-RG1`
-VMName VM1 `
-Location northeurope `
-FileUri https://raw.githubusercontent.com/x/assets/master/PowerShell/PS1/PS1/PS1.ps1 `
-Run 'PS1.ps1' `
-Name PS1
PS1.ps:
param
(
[Parameter(Mandatory)]
[String]$NewFileLocation
)
New-Item $NewFileLocation
推荐答案
这是我正在使用的:
Param (
[string]$location = $env:location,
...
[string]$tagEnvironment = $env:tagEnvironment
)
我正在使用VSTS库变量组,您可以将变量组链接到不同的发布管道.
I'm using VSTS Library Variable groups, you can link variable groups to different release pipelines.
这篇关于VSTS将变量传递到Azure PowerShell脚本参数中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!