【问题标题】:Azure DevOps - YAML Pipeline with multiple jobs syntax errorAzure DevOps - 具有多个作业语法错误的 YAML 管道
【发布时间】:2021-01-09 03:46:20
【问题描述】:

我有一个尝试运行多个作业的 YAML 管道,但我收到第一个任务(GitVesion 命令行任务)的语法错误,而我在其他管道中没有我有一份工作。

我得到的错误是:

(Line: 29, Col: 18, Idx: 576) - (Line: 29, Col: 18, Idx: 576): Mapping values are not allowed in this context.

第 29 行是第一个任务的 displayName(实际管道在文件顶部有 cmets,已在下面删除)。

trigger:
- master

pool:
  name: NameRedacted
  demands: VisualStudio_15.0

variables:
- name: CreateRelease
  value: true
- name: PublishPackages
  value: true
- name: PublishMyGetPackages
  value: true
- name: IntegrationTests_SqlAlias
  value: .
- group: 'Common Variables'

jobs:

- job: Backend
  steps:
  - task: CmdLine@1
      displayName: GitVersion
      inputs:
      filename: '$(GitVersionPath)'
      arguments: '$(GitVersionArguments)'

  - task: DeleteFiles@1
      displayName: 'Delete files from $(Build.ArtifactStagingDirectory)'
      inputs:
      SourceFolder: '$(Build.ArtifactStagingDirectory)'
      Contents: '**/*.nupkg'

  - task: DeleteFiles@1
      displayName: 'Delete files from $(Build.Repository.LocalPath)'
      inputs:
      SourceFolder: '$(Build.Repository.LocalPath)'
      Contents: |
          **/*.nupkg
          Packages/*.zip

  - task: DeleteFiles@1
      displayName: 'Delete old test files'
      inputs:
      SourceFolder: '$(System.DefaultWorkingDirectory)'
      Contents: '**\*test*.dll'

  - task: UseDotNet@2
      displayName: 'Use .Net Core SDK 2.2.104'
      inputs:
      packageType: sdk
      version: 2.2.104
      installationPath: $(Agent.ToolsDirectory)/dotnet

  - task: DotNetCoreCLI@2
      displayName: Restore
      inputs:
      command: restore
      projects: NameRedacted.sln
      restoreArguments: '$(DotNetRestoreSourcesLight)'

  - task: DotNetCoreCLI@2
      displayName: Build
      inputs:
      command: build
      projects: NameRedacted.sln
      arguments: '-c Release --no-restore'

  - task: DotNetCoreCLI@2
      displayName: Test
      inputs:
      command: 'test'
      projects: |
          **/*tests*/*.csproj
          !**\*Tests.Common.csproj
          !**\*Tests.Common.dll
          !**\*TestAdapter.dll
          !**\obj\**
          !**\netstandard2.0\*.dll
          !**\node_modules\**
      arguments: '-c Release'

  - task: DotNetCoreCLI@2
      displayName: Publish
      inputs:
        command: publish
        arguments: '-c $(BuildConfiguration) -o $(Build.ArtifactStagingDirectory) --no-restore'
        zipAfterPublish: false

  # Octopus packaging and pushing redacted

- job: 'Angular App'
  steps:
  - task: DeleteFiles@1
    displayName: 'Delete files from $(Build.ArtifactStagingDirectory)'
    inputs:
      SourceFolder: '$(Build.ArtifactStagingDirectory)'
      Contents: '**/*.nupkg'

  - task: DeleteFiles@1
    displayName: 'Delete tests '
    inputs:
      SourceFolder: '$(Parameters.SourceFolder)'
      Contents: '**/TESTS-*.xml'

  - task: DeleteFiles@1
    displayName: 'Delete files from dist'
    inputs:
      SourceFolder: '$(Parameters.SourceFolder)'
      Contents: dist

  - task: CmdLine@1
    displayName: 'Run $(GitVersionPath)'
    inputs:
      filename: '$(GitVersionPath)'
      arguments: '$(GitVersionArguments)'

  - task: NodeTool@0
    displayName: 'Use Node 10.x'
    inputs:
      versionSpec: 10.x

  - task: Npm@1
    displayName: 'npm install windows-build-tools'
    inputs:
      command: custom
      verbose: false
      customCommand: 'install --global --production windows-build-tools'

  - task: Npm@1
    displayName: 'npm install node-sass'
    inputs:
      command: custom
      verbose: false
      customCommand: 'install --global  --unsafe-perms node-sass'

  - task: Npm@1
    displayName: Restore
    inputs:
      workingDir: '$(Parameters.SourceFolder)'
      verbose: false

  - task: Npm@1
    displayName: Build
    inputs:
      command: custom
      workingDir: '$(Parameters.SourceFolder)'
      verbose: false
      customCommand: 'run ui-prod'

  - task: Npm@1
    displayName: Test
    inputs:
      command: custom
      workingDir: '$(Parameters.SourceFolder)'
      verbose: false
      customCommand: 'test --watch=false --single-run=true --reporters=junit,progress --browsers=PhantomJS'
    enabled: false

  - task: PublishTestResults@2
    displayName: 'Publish Test Results **/TESTS-*.xml'
    inputs:
      testResultsFiles: '**/TESTS-*.xml'
    enabled: false
    condition: succeededOrFailed()

  - task: Npm@1
    displayName: Lint
    inputs:
      command: custom
      workingDir: '$(Parameters.SourceFolder)'
      verbose: false
      customCommand: 'run lint'
    enabled: false

# Octopus packaging and pushing redacted

- job: 'Ionic App'
  steps:
  - task: DeleteFiles@1
    displayName: 'Delete files from $(Build.ArtifactStagingDirectory)'
    inputs:
      SourceFolder: '$(Build.ArtifactStagingDirectory)'
      Contents: '**/*.nupkg'

  - task: DeleteFiles@1
    displayName: 'Delete tests'
    inputs:
      SourceFolder: '$(Parameters.SourceFolder)'
      Contents: '**/TESTS-*.xml'

  - task: DeleteFiles@1
    displayName: 'Delete files from dist'
    inputs:
      SourceFolder: 'src/ionic-app'
      Contents: www

  - task: CmdLine@1
    displayName: 'Run $(GitVersionPath)'
    inputs:
      filename: '$(GitVersionPath)'
      arguments: '$(GitVersionArguments)'

  - task: NodeTool@0
    displayName: 'Use Node 10.x'
    inputs:
      versionSpec: 10.x

  - task: Npm@1
    displayName: 'npm install windows-build-tools'
    inputs:
      command: custom
      verbose: false
      customCommand: 'install --global --production windows-build-tools'

  - task: Npm@1
    displayName: 'npm install node-sass'
    inputs:
      command: custom
      verbose: false
      customCommand: 'install --global  --unsafe-perms node-sass'

  - task: Npm@1
    displayName: 'npm install ionic'
    inputs:
      command: custom
      verbose: false
      customCommand: 'install --global  ionic'

  - task: Npm@1
    displayName: Restore
    inputs:
      workingDir: 'src/ionic-app'
      verbose: false

  - task: Npm@1
    displayName: Build
    inputs:
      command: custom
      workingDir: 'src/ionic-app'
      verbose: false
      customCommand: 'run build-web-prod'

  # Octopus packaging and pushing redacted

- job: Release
  dependsOn:
    - Backedn
    - 'Angular App'
    - 'Ionic App'
  steps:
  - task: CmdLine@1
    displayName: 'Run $(GitVersionPath)'
    inputs:
      filename: '$(GitVersionPath)'
      arguments: '$(GitVersionArguments)'
    condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'), eq(variables['CreateRelease'],'true'), ne(variables['Build.Reason'], 'Schedule'))

  # Octopus release creating redacted

【问题讨论】:

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


    【解决方案1】:

    您有 3 个问题:

    1. displayName 应与task 对齐。
    2. inputs 之后的键应该在 inputs 的右侧,并且不对齐。
    3. job 名称不能包含空格。

    我为你修好了,这是正确的:

    trigger:
    - master
    
    pool:
      name: NameRedacted
      demands: VisualStudio_15.0
    
    variables:
    - name: CreateRelease
      value: true
    - name: PublishPackages
      value: true
    - name: PublishMyGetPackages
      value: true
    - name: IntegrationTests_SqlAlias
      value: .
    - group: 'Common Variables'
    
    jobs:
    
    - job: Backend
      steps:
      - task: CmdLine@1
        displayName: GitVersion
        inputs:
          filename: '$(GitVersionPath)'
          arguments: '$(GitVersionArguments)'
    
      - task: DeleteFiles@1
        displayName: 'Delete files from $(Build.ArtifactStagingDirectory)'
        inputs:
          SourceFolder: '$(Build.ArtifactStagingDirectory)'
          Contents: '**/Naus*.nupkg'
    
      - task: DeleteFiles@1
        displayName: 'Delete files from $(Build.Repository.LocalPath)'
        inputs:
          SourceFolder: '$(Build.Repository.LocalPath)'
          Contents: |
              **/*.nupkg
              Packages/*.zip
    
      - task: DeleteFiles@1
        displayName: 'Delete old test files'
        inputs:
          SourceFolder: '$(System.DefaultWorkingDirectory)'
          Contents: '**\*test*.dll'
    
      - task: UseDotNet@2
        displayName: 'Use .Net Core SDK 2.2.104'
        inputs:
          packageType: sdk
          version: 2.2.104
          installationPath: $(Agent.ToolsDirectory)/dotnet
    
      - task: DotNetCoreCLI@2
        displayName: Restore
        inputs:
          command: restore
          projects: NameRedacted.sln
          restoreArguments: '$(DotNetRestoreSourcesLight)'
    
      - task: DotNetCoreCLI@2
        displayName: Build
        inputs:
          command: build
          projects: NameRedacted.sln
          arguments: '-c Release --no-restore'
    
      - task: DotNetCoreCLI@2
        displayName: Test
        inputs:
          command: 'test'
          projects: |
              **/*tests*/*.csproj
              !**\*Tests.Common.csproj
              !**\*Tests.Common.dll
              !**\*TestAdapter.dll
              !**\obj\**
              !**\netstandard2.0\*.dll
              !**\node_modules\**
          arguments: '-c Release'
    
      - task: DotNetCoreCLI@2
        displayName: Publish
        inputs:
          command: publish
          arguments: '-c $(BuildConfiguration) -o $(Build.ArtifactStagingDirectory) --no-restore'
          zipAfterPublish: false
    
      # Octopus packaging and pushing redacted
    
    - job: AngularApp
      steps:
      - task: DeleteFiles@1
        displayName: 'Delete files from $(Build.ArtifactStagingDirectory)'
        inputs:
          SourceFolder: '$(Build.ArtifactStagingDirectory)'
          Contents: '**/*.nupkg'
    
      - task: DeleteFiles@1
        displayName: 'Delete tests '
        inputs:
          SourceFolder: '$(Parameters.SourceFolder)'
          Contents: '**/TESTS-*.xml'
    
      - task: DeleteFiles@1
        displayName: 'Delete files from dist'
        inputs:
          SourceFolder: '$(Parameters.SourceFolder)'
          Contents: dist
    
      - task: CmdLine@1
        displayName: 'Run $(GitVersionPath)'
        inputs:
          filename: '$(GitVersionPath)'
          arguments: '$(GitVersionArguments)'
    
      - task: NodeTool@0
        displayName: 'Use Node 10.x'
        inputs:
          versionSpec: 10.x
    
      - task: Npm@1
        displayName: 'npm install windows-build-tools'
        inputs:
          command: custom
          verbose: false
          customCommand: 'install --global --production windows-build-tools'
    
      - task: Npm@1
        displayName: 'npm install node-sass'
        inputs:
          command: custom
          verbose: false
          customCommand: 'install --global  --unsafe-perms node-sass'
    
      - task: Npm@1
        displayName: Restore
        inputs:
          workingDir: '$(Parameters.SourceFolder)'
          verbose: false
    
      - task: Npm@1
        displayName: Build
        inputs:
          command: custom
          workingDir: '$(Parameters.SourceFolder)'
          verbose: false
          customCommand: 'run ui-prod'
    
      - task: Npm@1
        displayName: Test
        inputs:
          command: custom
          workingDir: '$(Parameters.SourceFolder)'
          verbose: false
          customCommand: 'test --watch=false --single-run=true --reporters=junit,progress --browsers=PhantomJS'
        enabled: false
    
      - task: PublishTestResults@2
        displayName: 'Publish Test Results **/TESTS-*.xml'
        inputs:
          testResultsFiles: '**/TESTS-*.xml'
        enabled: false
        condition: succeededOrFailed()
    
      - task: Npm@1
        displayName: Lint
        inputs:
          command: custom
          workingDir: '$(Parameters.SourceFolder)'
          verbose: false
          customCommand: 'run lint'
        enabled: false
    
    # Octopus packaging and pushing redacted
    
    - job: IonicApp
      steps:
      - task: DeleteFiles@1
        displayName: 'Delete files from $(Build.ArtifactStagingDirectory)'
        inputs:
          SourceFolder: '$(Build.ArtifactStagingDirectory)'
          Contents: '**/Naus*.nupkg'
    
      - task: DeleteFiles@1
        displayName: 'Delete tests'
        inputs:
          SourceFolder: '$(Parameters.SourceFolder)'
          Contents: '**/TESTS-*.xml'
    
      - task: DeleteFiles@1
        displayName: 'Delete files from dist'
        inputs:
          SourceFolder: 'src/ionic-app'
          Contents: www
    
      - task: CmdLine@1
        displayName: 'Run $(GitVersionPath)'
        inputs:
          filename: '$(GitVersionPath)'
          arguments: '$(GitVersionArguments)'
    
      - task: NodeTool@0
        displayName: 'Use Node 10.x'
        inputs:
          versionSpec: 10.x
    
      - task: Npm@1
        displayName: 'npm install windows-build-tools'
        inputs:
          command: custom
          verbose: false
          customCommand: 'install --global --production windows-build-tools'
    
      - task: Npm@1
        displayName: 'npm install node-sass'
        inputs:
          command: custom
          verbose: false
          customCommand: 'install --global  --unsafe-perms node-sass'
    
      - task: Npm@1
        displayName: 'npm install ionic'
        inputs:
          command: custom
          verbose: false
          customCommand: 'install --global  ionic'
    
      - task: Npm@1
        displayName: Restore
        inputs:
          workingDir: 'src/naus-residents-app'
          verbose: false
    
      - task: Npm@1
        displayName: Build
        inputs:
          command: custom
          workingDir: 'src/naus-residents-app'
          verbose: false
          customCommand: 'run build-web-prod'
    
      # Octopus packaging and pushing redacted
    
    - job: Release
      dependsOn:
        - Backedn
        - 'Angular App'
        - 'Ionic App'
      steps:
      - task: CmdLine@1
        displayName: 'Run $(GitVersionPath)'
        inputs:
          filename: '$(GitVersionPath)'
          arguments: '$(GitVersionArguments)'
        condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'), eq(variables['CreateRelease'],'true'), ne(variables['Build.Reason'], 'Schedule'))
    
      # Octopus release creating redacted
    

    【讨论】:

      【解决方案2】:

      我相信您的displayName 键应该与您的task 键的第一个字符对齐:

      
      - job: Backend
        steps:
        - task: CmdLine@1
          displayName: GitVersion
          inputs:
          filename: '$(GitVersionPath)'
          arguments: '$(GitVersionArguments)'
      
        - task: DeleteFiles@1
          displayName: 'Delete files from $(Build.ArtifactStagingDirectory)'
          inputs:
          SourceFolder: '$(Build.ArtifactStagingDirectory)'
          Contents: '**/Naus*.nupkg'
      

      【讨论】:

        猜你喜欢
        • 2020-09-15
        • 2019-05-14
        • 1970-01-01
        • 1970-01-01
        • 2022-09-23
        • 2020-05-23
        • 1970-01-01
        • 2020-10-26
        • 1970-01-01
        相关资源
        最近更新 更多