代码之家  ›  专栏  ›  技术社区  ›  user989988

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

  •  0
  • user989988  · 技术社区  · 4 年前

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

    我在跟踪这个医生 https://docs.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
    

    enter image description here

    0 回复  |  直到 4 年前
        1
  •  4
  •   Roderick Bant    4 年前

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

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

    在下一页中,选择 Grant authorization 如果尚未选择。选择 AzurePipelines 有关OAuth配置,请单击 Authorize 。确认GitHub弹出窗口并输入您的GitHub凭据。下一次点击 Authorize Azure pipelines 在GitHUb授权对话框上。然后回到Azure DevOps页面,记下服务连接名称以供以后参考,然后单击 Save 完成服务连接的创建。

    然后回到你的 azure管道。亚马尔 编辑如下:

    resources:
      repositories:
      - repository: MyGitHubRepo
        type: github
        endpoint: name_of_service_connection_you_created
        name: github-user-name/repo-name
        ref: master
    

    一定要把灯调好 type 到GitHub并注意设置 name 您的GitHub用户名和存储库名称组合的值,如 username/reponame .

    中存储库资源的参考 azure管道。亚马尔 可以在 YAML schema

    可以找到创建的文档 here

        2
  •  1
  •   Vito Liu    4 年前

    步骤:

    登录 GitHub Token 翻页并创建PAT令牌。

    打开项目设置->服务连接->点击按钮 New service connection 并选择GitHub类型以创建GitHub连接。

    enter image description here

    我分享的示例是将GitHub repo发布为工件。

    GitHub回购。

    enter image description here

    YAML样本:

    resources:
      repositories:
      - repository: vitol
        type: github
        endpoint: GithubTest
        name:  vitoliutest/vitol
    
    trigger:
      - none
    pool:
      name: Hosted Ubuntu 1604
    steps:
      - checkout: vitol
      - task: CopyFiles@2
        inputs:
          SourceFolder: '$(Agent.BuildDirectory)'
          Contents: '**'
          TargetFolder: '$(build.artifactstagingdirectory)'
        
      - task: PublishBuildArtifacts@1
        inputs:
          PathtoPublish: '$(build.artifactstagingdirectory)'
          ArtifactName: 'drop'
          publishLocation: 'Container'
    

    注意:请注意步骤 checkout ,用于签出GitHub回购协议。

    后果

    enter image description here