8

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 Answer 1

12

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

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

Comments

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.