我目前有一个可用的 YAML ARM 模板,其中包含以下内容:
- task: PowerShell@2
displayName: "Do My Stuff"
inputs:
targetType: 'filePath'
pwsh: true
filePath: '$(Build.SourcesDirectory)/Do-MyStuff.ps1'
arguments: >-
-SourcesDirectory $(Build.SourcesDirectory)
-Foo hello
-Bar world
但是现在我想访问 $Build 变量的其他属性,但是当我这样做时
- task: PowerShell@2
displayName: "Do My Stuff"
inputs:
targetType: 'filePath'
pwsh: true
filePath: '$(Build.SourcesDirectory)/Do-MyStuff.ps1'
arguments: >-
-Build $(Build)
-Foo hello
-Bar world
(并更新 Do-MyStuff.ps1)
我收到错误:
Build:术语“Build”不被识别为 cmdlet、函数、脚本文件或可操作程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。
有人知道我可以做什么,以便我可以将 $Build 传递给我的 PowerShell 脚本吗?
最佳答案
事实证明,ARM 认为 Build.
只是变量名称的一部分。
它不是一个结构。
如果你想传入多个值,你可以这样做:
- task: PowerShell@2
displayName: "Do My Stuff"
inputs:
targetType: 'filePath'
pwsh: true
filePath: '$(Build.SourcesDirectory)/Do-MyStuff.ps1'
arguments: >-
-Build @{
'SourcesDirectory' = '$(Build.SourcesDirectory)';
'ArtifactStagingDirectory' = '$(Build.ArtifactStagingDirectory)';
}
-Foo hello
-Bar world
脚本将采用如下参数:
[Parameter(Mandatory = $true, Position = 0)]
[hashtable]
$Build,
关于Azure YAML ARM 模板 - 将 $Build 传递到 PowerShell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62806979/