0
votes

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: Allow scripts OAuth

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:

enter image description here

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:

Pipeline YAML Code

  • 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

1 Answers

1
votes

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 "[email protected]"
      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