azure - 在 Yaml 文件中使用 powershell 内联脚本时出现错误 "while parsing a block mapping did not find expected key"

标签 azure azure-devops yaml azure-pipelines-yaml

Yaml 使用起来确实令人沮丧,我从 azure devops 发布管道导出为 YAML,每次我将此代码插入到我的 yaml 文件中并运行它时,Azure devops 总是说“错误 - 解析 block 映射时未找到预期的关键”。有人能够帮助了解如何在 yaml 中包含内联 powershell 脚本,因为 Azure Devops 中的导出 yaml 选项毫无用处

 - task: AzurePowerShell@5
   displayName: 'test inline script in yaml'
   inputs:
   azureSubscription: 'azuresubscriptionid'
   ScriptType: InlineScript
   Inline: |
     # Setting Variables
     $var1 = "1!
     Write-Output $var1
   preferredAzurePowerShellVersion: 3.1.0

最佳答案

请在下面找到正确的脚本:

  - task: AzurePowerShell@5
    displayName: 'test inline script in yaml'
    inputs:
      azureSubscription: 'azuresubscriptionid'
      ScriptType: InlineScript
      Inline: |
        # Setting Variables
        $var1 = "1"
        Write-Output $var1
      preferredAzurePowerShellVersion: 3.1.0

inputs: 之后有一个额外的缩进

请查看documentation .

Online Validator

enter image description here

感谢@vince-bowdren 关于脚本中的拼写错误。

关于azure - 在 Yaml 文件中使用 powershell 内联脚本时出现错误 "while parsing a block mapping did not find expected key",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72546486/

相关文章:

c# - 在 VSTS 上构建 MonoGame 项目

macos - 错误 : there was a problem with the editor "vi" -- while trying to edit a deployment file in a cluster

windows - 如何将通配符域映射到 Windows Azure 网站实例?

azure 连接的虚拟机远程桌面

Azure 负载均衡器

azure-devops - 在 azure devops 中,我们如何知道发布候选中有哪些故事?

azure - Azure Static WebApp 可以从 Azure 容器注册表中提取镜像吗?

r - R : (Package which is only available in source form, 错误,可能需要编译 C/C++/Fortran)

amazon-web-services - 如何通过 CloudFormation YAML 将堆栈导出的现有 S3 存储桶导入另一个堆栈

azure - 将 Azure 应用程序 Insight 日志文件导出到 Azure Data Lake 存储