Azure pipelines read file from resources repository

Viewed 4488

I am referencing a repository in my azure-pipelines template like this:

resources:
  repositories:

    - repository: MyRepo
      type: git
      name: MyRepoName
      ref: MyRepoRef

I would like to know if it is possible to read the content of a file that is inside the referenced repository, inside this repository is another yaml that is being executed in the pipeline.

1 Answers

If we use another repo in the pipeline, we could read the content of a file in the referenced repository. We could refer this link for more details

In my test, project name is test, the referenced repository is test and current repository is sample, then I read the content of file pull_request_template.md

YAML build definition:

trigger: none

resources:
  repositories:
  - repository: test
    type: git
    name: test/test
    ref: master

steps:
#checkout referenced repository
  - checkout: test
#List SourcesDirectory files
  - task: Bash@3
    inputs:
      targetType: 'inline'
      script: 'ls ''$(Build.SourcesDirectory)'''
#Read the contents of the file pull_request_template.md
  - task: PowerShell@2
    inputs:
      targetType: 'inline'
      script: 'Get-Content -Path $(Build.SourcesDirectory)\pull_request_template.md'

Result:

enter image description here

Related