查看 ADO 管道中的 github 存储库 [YAML]

use*_*060 2 git yaml github repository azure-devops

我有一个 github 存储库:https ://github.com/user-name/repo-name

我正在按照此文档https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops#faq来签出多个存储库。这是我的 yaml 文件:

name: 1.0

resources:
  repositories:
  - repository: MyGitHubRepo
    type: github
    endpoint: https://github.com/user-name/repo-name
    name: repo-name
    ref: master

trigger:
- master
- develop
- features/*

pool:
  vmImage: "vs2017-win2016"

variables:
  "BuildConfiguration": 'debug'
  "BuildPlatform": 'any cpu'

stages:

- checkout: MyGitHubRepo
- template: build.yml@MyGitHubRepo
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Rod*_*ant 5

问题出在repositories.endpoint设置上。该endpoint设置应引用 Azure Devops Project Service connection。项目服务连接是对 Azure DevOps 中项目级别的服务或资源的引用,它允许您存储凭据等以安全地引用资源和服务,而无需在代码中存储这些资源的凭据。特定的 Azure 管道任务和 azure-pipelines.yaml属性可以轻松引用服务连接。

要设置服务连接,请Project settings在 Azure DevOps 项目中单击浏览器中页面底部的 。然后在左侧菜单中Pipelines点击Service connections。在页面右上角单击New service connection并选择GitHub并单击Next

在下一页上,Grant authorization如果尚未选择,请选择。选择AzurePipelinesOAuth 配置并单击Authorize。确认 GitHub 弹出窗口并输入您的 GitHub 凭据即可执行此操作。接下来单击Authorize Azure pipelinesGitHub 授权对话框。然后返回 Azure DevOps 页面,记下服务连接名称以供稍后参考,然后单击Save以完成服务连接的创建。

然后回到您的azure-pipelines.yaml编辑,如下所示:

resources:
  repositories:
  - repository: MyGitHubRepo
    type: github
    endpoint: name_of_service_connection_you_created
    name: github-user-name/repo-name
    ref: master
Run Code Online (Sandbox Code Playgroud)

确保将 设为typeGitHub,并注意将该name值设置为 GitHub 用户名和存储库名称的组合,例如username/reponame

可以在YAML 架构azure-pipelines.yaml中找到存储库资源的参考

可以在此处找到创建文档