0
votes

I am trying to follow the solution given in the following link: How to fix Github to Azure DevOps Sync?

My requirement is to trigger Azure Devops pipeline when a commit is done in any branch of GitHub repository. I have already imported the code from GitHub repository using PAT token from GitHub repo. The PAT token is given all access in GitHub repository.

But I am getting the following error: enter image description here

Following is my pipeline yaml code:

trigger:
  branches:
    include:
    - '*'
variables:
  system_accesstoken: $(System.AccessToken)

pool:
  vmImage: 'ubuntu-latest'

steps:
- checkout: self
  persistCredentials: true    #Allow scripts to access the system token
  clean: true 

- task: Bash@3
  name: SyncRepo
  inputs:
    targetType: 'inline'
    script: |
      git config --global user.email "[email protected]"
      git config --global user.name "sormita"
      git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
      git remote add vsts https://xxx.visualstudio.com/xxx/_git/xxxx
      git branch -r | grep -v '\->' | while read remote; do git -c http.extraheader="AUTHORIZATION: bearer $(system_accesstoken)" push -u vsts "${remote#origin/}"; done

Can someone please help me synchronize GitHub repository with Azure Devops repo?

1

1 Answers

1
votes

It should caused by your account do not have the contribute permission for this repository.

Go Project settings --> Repositories --> click Repos you want to operate -->check the service account {project name} Build Service (xxx) and ensure the permission is set to allow. You could check the pic below.

enter image description here

Result:

enter image description here

Update1

Create yaml pipeline in the Azure DevOps, we need select GitHub as the code resource, then select GitHub repository, it will save the yaml file in the GitHub Repo instead of Azure DevOps repo, then we could see the CI trigger.

Note: If the yml file save in the Azure DevOps repo, it will not trigger the build if we push code in the GitHub

enter image description here

Result:

enter image description here