Azure管道从资源存储库读取文件

标签 azure azure-devops

我在我的 azure-pipelines 模板中引用存储库,如下所示:

resources:
  repositories:

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

我想知道是否可以读取引用存储库内的文件内容,该存储库内是另一个正在管道中执行的 yaml。

最佳答案

如果我们在管道中使用另一个存储库,我们可以读取引用的存储库中文件的内容。我们可以引用这个link了解更多详情

在我的测试中,项目名称是test,引用的存储库是test,当前存储库是sample,然后我读取了内容文件pull_request_template.md

YAML 构建定义:

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'

结果:

enter image description here

关于Azure管道从资源存储库读取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65674610/

相关文章:

azure - VSTS - Docker/容器工作

azure - 在 Visual Studio 中本地使用 Azure 发布管道变量(调试时)

powershell - 用于本地应用程序的在线 Visual Studio

azure - 从 Azure 管道任务访问 Microsoft.Azure.WebSites 资源提供程序(Microsoft Azure 应用服务)的服务主体

azure - 为 Web 应用程序创建新的 Azure 应用程序服务计划时出错

azure - 如何以编程方式访问 Azure 管理服务 "operations log"?

git - 在 Visual Studio Online 上托管 bower 组件

azure - 从 Azure Function 调用 Azure SQL 数据库时出现暂时性错误

azure - 部署槽设置如何在 Azure 应用服务上发挥作用?

azure-devops - Azure DevOps yaml 管道 : how to download only specific artifacts of a referenced pipeline?