How to fix Github to Azure DevOps Sync?

≡放荡痞女 提交于 2021-02-07 04:37:40

问题


I have a synchronization between Azure DevOps and Github to sync the Github repo with the repo in Azure Devops. End of last year everything works fine. This year the synchronization do not work anymore. The failure message was fatal: could not read Password for 'https://$(XXXXXXXXXToken)@yyyyyy.visualstudio.com': terminal prompts disabled'

I have forgotten, that the PAT expires on 31.12.2019. So I recreated the pipeline, instead of just changing the expiration date of the PAT. facepalm. My idea was to create a new pipeline to get to the point which the problem cause. But I think I made everything worst.

Now I changed the Script from:

git push https://$(XXXXXXXToken)@yyyyyy.visualstudio.com/nnnnn/_git/kkkkkkkk -u --all

to:

git push https://$(System.AccessToken)@yyyyyy.visualstudio.com/nnnnn/_git/kkkkkkkk -u --all

I changed the token to 'System.AccessToken', because information at "Allow scripts to access the OAuth token" says:

I revoked every PAT in my list. After I recreated the pipeline and changed the access to 'System.AccessToken' DevOps automatically creates a PAT, which looks like:

The Pipeline runs green, but the Azure DevOps git repo is still not updated. It seems, there is still no connection to the Azure DevOps git repo. The log of the pipeline shows me, that checking out from the github repo works fine. No failures.

The Pipeline YAML code (I have created the pipeline with the UI not directyl with the YAML editor) is:

  • On Github site I installed the Azure Pipelines and Azure Boards App.
  • I also authorized both apps and authorized both apps to OAuth.
  • I also have a Webhok between GitHub and the Azure DevOps repo. The Webhook is configured for Pull requests, Pushes and Releases
  • In Azure DevOps there is a GitHub connection to all my Repos in GitHub.

Can someone help me to get the sync working correctly?


回答1:


We have to declare a variable in YAML to access the $(System.AccessToken). See Set variables in pipeline

I can sync the Github repo successfully to Azure DevOps repo using the following YAML pipeline: (Just replace the Azure DevOps git repo accordingly : https://xxx.visualstudio.com/GithubSync/_git/GithubSync)

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: shellexec@0
  inputs:
    code: |
      git config --global user.email "xx@xx.com"
      git config --global user.name "xxx"
      git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
      git remote add vsts https://xxx.visualstudio.com/GithubSync/_git/GithubSync
      git branch -r | grep -v '\->' | while read remote; do git -c http.extraheader="AUTHORIZATION: bearer $(system_accesstoken)" push -u vsts "${remote#origin/}"; done

Reference this blog for more information : SYNCHRONIZE GITHUB REPOSITORY WITH VSTS



来源:https://stackoverflow.com/questions/59618979/how-to-fix-github-to-azure-devops-sync

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!