1
votes

I have a github repository: https://github.com/user-name/repo-name

I'm following this doc https://docs.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops#faq to checkout multiple repositories. Here is my yaml file:

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

2
Hi, Just checking in to see whether this issue is still blocking you now? Any update for this issue? Feel free to let me know if you have any questions.Vito Liu
Hi, thank you for checking in. Question - The yaml file in my example is located in an ADO repo and I need to checkout a GitHub repo. I'm still confused on the service connection part.user989988
Hi, I have shared the detailed steps in my answer, please check it and kindly share the result here.Vito Liu
Hi, I recommend that you create a new ticket, then share the yaml build definition, GitHub yml file and error log. We need check it and help you. Thanks.Vito Liu
@VitoLiu-MSFT Could you please answer stackoverflow.com/questions/64867728/…user989988

2 Answers

2
votes

The issue is in the repositories.endpoint setting. The endpoint setting should reference an Azure Devops Project Service connection. A project service connection is a reference to a service or resource at the project level in Azure DevOps that allows you to store credentials etc for referencing resources and services safely without the need for storing credentials for those resources in your code. Specific Azure pipeline tasks and azure-pipelines.yaml properties can easily reference the service connections.

To set up a service connection, click Project settings at the bottom of the page in the browser while in your Azure DevOps project. Then in the left menu under Pipelines click Service connections. At the top right of the page click New service connection and choose GitHub and click Next

On the next page, select Grant authorization if it is not already selected. Choose AzurePipelines for the OAuth Configuration and click Authorize. Confirm the GitHub pop-up and enter your GitHub credentials to do so. Next click Authorize Azure pipelines on the GitHUb authorization dialog. Then back on the Azure DevOps page take note of the service connection name for reference later on and click Save to finish creating the service connection.

Then back to your azure-pipelines.yaml edit as below:

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

Make sure to set the type to GitHub and take care to set the name value to the combination of your GitHub user name and repository name like username/reponame.

Reference for the repository resource in azure-pipelines.yaml can be found in the YAML schema

Documentation for creating can be found here

1
votes

Steps:

Login GitHub Token page and create PAT Token.

Open project settings->Service connections->Click the button New service connection and select GitHub type to create GitHub connection.

enter image description here

The sample I shared is publish GitHub repo as Artifacts.

GitHub repo.

enter image description here

YAML sample:

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'

Note: Please notice the step checkout, it is used to checkout GitHub repo.

Result

enter image description here