Azure DevOps 管道上的 YAML 解析器错误

YAML Parser error on Azure DevOps Pipeline

我在我的 azure devop 管道上收到以下错误,它似乎与参数循环有关,但尽管以多种不同的方式编写脚本,但我似乎无法摆脱它。 YAML 验证器和我的 YAML linter 没有检测到问题。

/azure-pipelines.yml (Line: 1, Col: 12): Unexpected value ''

下面是我的代码,它也使用了一个模板,我将把它放在下面。

蔚蓝-pipelines.yml

parameters:
steps:
- ${{ each project in parameters.projects }}:
  - task: UsePythonVersion@0
    displayName: 'Setting python version to 3.7'
    inputs:
      versionSpec: '3.7'
      architecture: 'x64'

  - script: |
      pushd '$(System.DefaultWorkingDirectory)/${{ project }}'
      pip install -r requirements.txt
    displayName: 'Install prerequisites'

  - task: ArchiveFiles@2
    displayName: 'Archive files'
    inputs:
      rootFolderOrFile: '$(System.DefaultWorkingDirectory)/${{ project }}'
      includeRootFolder: false
      archiveFile: '$(System.DefaultWorkingDirectory)/${{ project }}.zip'

  - task: PublishBuildArtifacts@1
    inputs:
      PathtoPublish: '$(System.DefaultWorkingDirectory)/${{ project }}.zip'
      artifactName: 'drop'

  - task: AzureResourceManagerTemplateDeployment@3
    displayName: 'ARM Template deployment: Resource Group scope'
    
    inputs:
      azureResourceManagerConnection: $(serviceConnectionName)
      subscriptionId: $(subscriptionId)
      resourceGroupName: $(resourceGroupName)
      location: $(resourceGroupLocation)
      csmFile: 'deployment_template.json'
      overrideParameters: '-appName ${{ project }} -storageAcctName $(storageAcctName)  -hostingPlanName $(hostingPlanName)'

  - task: AzureFunctionApp@1
    inputs:
      azureSubscription: $(serviceConnectionName)
      appType: functionAppLinux
      appName: ${{ project }}
      package: '$(System.DefaultWorkingDirectory)/${{ project }}.zip'

模板 - 部署-functions.yml

trigger:
  - main

variables:
  - group: 'AzFunctionsAppVariableGroup'
    
pool:
  vmImage: ubuntu-18.04
  
steps:
- template: azure-pipelines.yml
  parameters:
    projects:
    - ProjectName1

如果我将您的 azure-pipelines.yml 放入 Azure DevOps 的管道编辑器中,它会标记 参数的行结尾: 警告

"Incorrect type. Expected "array"."

到目前为止我还没有在管道上使用模板,但是从 MS doc page 来看,您似乎需要像这样指定要传递的参数:

#azure-pipelines.yml

parameters:
- name: projects
  type: object #object, since you are passing a list of strings
steps:
- ${{ each project in parameters.projects }}:
#...

建议您开启YAML模板编辑器功能,如下图进行测试。