Azure YAML ARM 模板 - 将 $Build 传递到 PowerShell 脚本

标签 azure yaml azure-rm-template

我目前有一个可用的 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/

相关文章:

visual-studio - 为什么 "Export to New Stream Analytics Project"被禁用

C# Yaml 处理

go - YAML Unmarshal map [string] struct

java - 无法在运行时更改 dropwizard 中的日志级别

Azure 搜索、listAdminKeys、ARM 输出错误(不支持 http 方法 'POST' )

Azure ARM 模板 - SQL 故障转移组错误 FailoverGroupCreateOrUpdateRequestReadOnlyPropertyModified

azure - ARM 模板清理

azure - 使用 azure_keyvault_secret 进行 Ansible 查找无效凭据

Azure 扩展事件目标文件

azure - 在 Azure 移动应用程序中向经过身份验证的用户添加其他声明