0

Hi I want to push my project to GitHub from Azure Team Foundation Server using Azure Pipelines.

I have tried same task (push project to GitHub) from Azure Git using Azure pipeline using below commands in PowerShell Command In-line;

Required Token: AZURE_PERSONAL_ACCESS_TOKEN & GITHUB_PERSONAL_ACCESS_TOKEN

Step1: git clone --mirror https://$(AZURE_PERSONAL_ACCESS_TOKEN )@$(AZURE_REPO_CLONE_URL)

Step2: git checkout -b master

Step3: $gitHubUrl = "https://$(GITHUB_PERSONAL_ACCESS_TOKEN )@$(GITHUB_REPO_CLONE_URL)"
                     if(($url)) { git remote add origin $gitUrl }
                     else { git remote set-url origin $gitUrl }

step4: git push --mirror "https://$(GITHUB_PERSONAL_ACCESS_TOKEN )@$(GITHUB_REPO_CLONE_URL)"

The above code works for push project to GITHUB from Azure Git but current Code not working for Azure TFS.

Rahul
  • 404
  • 4
  • 16
  • I would suggest to create the pipeline on the TFVC repository so that the code is checked out from it. Then you could download the Github repository that you need on a specific folder and synchronize the changes with it. Then using the code you provided you could push back to the needed git repository. – GeralexGR Feb 02 '22 at 15:12

1 Answers1

0

Please make sure you can access to the GitHub repo from your agent server first. Just try to run the push command on your agent machine to check if you can push the changes to the Github repo.

If you can push the commits to the Github repo from the agent server locally.Then you can try to setup a CI pipeline by referencing below YAML file. Then check if it works. (Note: you need to install Shell exec task)

trigger:
 - main

variables:
  github_token: $(GITHUB_PERSONAL_ACCESS_TOKEN)

pool:
  vmImage: 'self-hosted-agent'

steps:
- checkout: self
  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 github https://GITHUB_REPO_CLONE_URL
      git branch -r | grep -v '\->' | while read remote; do git -c http.extraheader="AUTHORIZATION: basic $(github_token)" push -u github "${remote#origin/}"; done

If that still doesn't work, then please reference this thread to check if it helps : How to synchronize VSTS and Github respositories when commits are made

Andy Li-MSFT
  • 28,712
  • 2
  • 33
  • 55