-1

My YAML file already contains a Resource section and now I want to add a pipeline to the resource section to trigger my publish pipeline after the PR pipeline is successful. THis works fine and the pipeline is trigger when a merge is made to the main branch

Here are the relevant sections as they stand now

trigger: 
  - main

---------- removed parameter and variable sections for brevity -----------

resources:
  repositories: 
    - repository: templates
      type: git
      name: OneBranch.Pipelines/GovernedTemplates
      ref: refs/heads/main

Based on several SO posts like this one: Azure Devops - How to call one pipeline from another

I modified the YAML as such:

trigger: 
  - none

---------- removed parameter and variable sections for brevity -----------

resources:
  repositories: 
    - repository: templates
      type: git
      name: OneBranch.Pipelines/GovernedTemplates
      ref: refs/heads/main
  pipelines:
    - pipeline: DRIContactManagement-Official  
      source: DRIContactManagement-PullRequest 
      trigger: true 

When I run the modified YAML, the pipeline fails with the error: (Line: 14, Col: 1): Did not find expected <document start>. The line number is right below the "trigger".

Any suggestions to fix this?

Update 1 To answer @brightran's question, here is the full section of the YAML

#################################################################################
#                         Pipelines - Official                        
#
# This pipeline was created  from a sample located at:              
#
#   https://aka/obpipelines/easystart/samples                                #
# Documentation:  https://aka/obpipelines                                    #
# Yaml Schema:    https://aka/obpipelines/yaml/schema                        #
# Retail Tasks:   https://aka/obpipelines/tasks                              #
# Support:        https://aka/onebranchsup                                   #
#################################################################################

trigger: 
  - none

parameters: # parameters are shown up in ADO UI in a build queue time
  - name: 'debug'
    displayName: 'Enable debug output'
    type: boolean
    default: false

variables:
  CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)] # needed for onebranch.pipeline.version task https://aka.ms/obpipelines/versioning
  system.debug: ${{ parameters.debug }}
  ENABLE_PRS_DELAYSIGN: 1
  ROOT: $(Build.SourcesDirectory)
  REPOROOT: $(Build.SourcesDirectory)
  OUTPUTROOT: $(REPOROOT)\out
  NUGET_XMLDOC_MODE: none

  WindowsContainerImage: 'onebranch.azurecr.io/windows/ltsc2019/vse2022:latest' # Docker image which is used to build the project https://aka/obpipelines/containers

resources:
  repositories: 
    - repository: templates
      type: git
      name: OneBranch.Pipelines/GovernedTemplates
      ref: refs/heads/main
  pipelines:
    - pipeline: DRIServiceUpdate-Official  # Name of the pipeline resource.
      source: DRIServiceUpdate-PullRequest # The name of the pipeline referenced by this pipeline resource.
      #project:  # Required only if the source pipeline is in another project
      trigger: true # Run app-ci pipeline when any run of security-lib-ci completes

Line 14 corresponds to the start of the Parameters: section. There are no other errors or logs from the build. I've tried to edit the YAML file in Azure DevOps so it will validate when I save the changes, but it always says its valid structure. I've also tried running it through some online validators and get the same result.

Update 2
The encoding was set to UTF-8 wo BOM so that was fine. I made minor changes to the indention as suggested and got a new error /.pipelines/DRIServiceUpdate-Official.yml (Line: 44, Col: 5): While parsing a block mapping, did not find expected key. Line 44 is "template:", in the "Extends" section.

trigger: main

parameters: # parameters are shown up in ADO UI in a build queue time
  - name: 'debug'
    displayName: 'Enable debug output'
    type: boolean
    default: false

variables:
  CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)] # needed for onebranch.pipeline.version task https://aka.ms/obpipelines/versioning
  system.debug: ${{ parameters.debug }}
  ENABLE_PRS_DELAYSIGN: 1
  ROOT: $(Build.SourcesDirectory)
  REPOROOT: $(Build.SourcesDirectory)
  OUTPUTROOT: $(REPOROOT)\out
  NUGET_XMLDOC_MODE: none

  WindowsContainerImage: 'onebranch.azurecr.io/windows/ltsc2019/vse2022:latest' # Docker image which is used to build the project https://aka.ms/obpipelines/containers

resources:
  repositories: 
    - repository: templates
      type: git
      name: OneBranch.Pipelines/GovernedTemplates
      ref: refs/heads/main
  pipelines:
    - pipeline: DRIServiceUpdate-Official  # Name of the pipeline resource.
      source: DRIServiceUpdate-PullRequest # The name of the pipeline referenced by this pipeline resource.
      #project:  # Required only if the source pipeline is in another project
      trigger: true # Run app-ci pipeline when any run of security-lib-ci completes

extends:
  template: v2/OneBranch.Official.CrossPlat.yml@templates # https://aka.ms/obpipelines/templates
  parameters:
    cloudvault: # https://aka.ms/obpipelines/cloudvault
      enabled: false
    globalSdl: # https://aka.ms/obpipelines/sdl
      asyncSdl:
        enabled: true
        tsaOptionsFile: .config/tsaoptions.json
      tsa:
        enabled: false # onebranch publish all sdl results to TSA. If TSA is disabled all SDL tools will forced into 'break' build mode.
      # credscan:
      #   suppressionsFile: $(Build.SourcesDirectory)\.config\CredScanSuppressions.json
      binskim:
        break: true # always break the build on binskim issues in addition to TSA upload
      policheck:
        break: true # always break the build on policheck issues. You can disable it by setting to 'false'
      # suppression:
      #   suppressionFile: $(Build.SourcesDirectory)\.gdn\global.gdnsuppress

I'm sure it's still a formatting issue but I can't see it.

Update 3 Ok, finally finished it. The last error was one line with incorrect indention. Which line doesn't matter but what I found was an awesome extension for VS Code https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml. This was recommended on another SO thread and after I installed it, the incorrect line was underlined in Red and that was that. I would highly recommend it.

Thanks Bright Ran for sticking with me on this problem

7
  • I attempted with the similar configurations of resources like as you in my YAML pipeline, and it can work fine. What is the content of the line (Line: 14) reported in the error message? Is there more detailed error messages/logs thrown out? Commented May 15, 2024 at 6:32
  • Hard to answer this because you're not showing the pipeline after line 14. My guess is indentation for the sections that you've excluded for brevity. Commented May 15, 2024 at 14:02
  • @bryanbcook I thought the same thing but if I remove the pipeline resource, and change nothing else, it runs fine. Commented May 15, 2024 at 14:07
  • I'm confused - are you saying that it validates fine, but it only fails when you run it? The title, description and steps to reproduce your situation are not clear at all. Commented May 15, 2024 at 14:26
  • Yes my title is bad and I'll fix that. The rest is all in the post. Thanks for the down-vote. Commented May 15, 2024 at 14:40

1 Answer 1

1

Try to check with the following things to fix the issue:

  1. Check the indentation in the YAML files. Normally, the child items are indented two whitespaces relative to the parent items. If the child items start with "- <keyName>:" (for example, - name: myVar), you can ignore the indentation. You can try to update your YAML like as below.

    trigger: none
    
    parameters:
    - name: debug
      displayName: 'Enable debug output'
      type: boolean
      default: false
    
    variables:
      CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)]
      system.debug: ${{ parameters.debug }}
      ENABLE_PRS_DELAYSIGN: 1
      ROOT: $(Build.SourcesDirectory)
      REPOROOT: $(Build.SourcesDirectory)
      OUTPUTROOT: $(REPOROOT)\out
      NUGET_XMLDOC_MODE: none
      WindowsContainerImage: 'onebranch.azurecr.io/windows/ltsc2019/vse2022:latest'
    
    resources:
      repositories: 
      - repository: templates
        type: git
        name: OneBranch.Pipelines/GovernedTemplates
        ref: refs/heads/main
      pipelines:
      - pipeline: DRIServiceUpdate-Official
        source: DRIServiceUpdate-PullRequest
        trigger: true
    
  2. Check the encoding of the YAML files. Try to change the encoding to UTF-8 Without BOM (UTF-8). You can download the YAML files to your local machine and open them on the text editor such VS Code, Notepad++, EmEditor, etc... Then re-save the YAML files with encoding UTF-8 Without BOM. Then push the updated YAML files back to Azure Repos.

    enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

I found a couple mentions of the UTF-8 with BOM encoding but couldn't figure out where to check it. Thanks for the screenshots.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.