问题
we are working on a project in our company; the project is managed in Azure DevOps (the "online" version, with git).
Let's call the project P1, in Azure DevOps for company C1.
This company DevOps can be accessed from anywhere, provided you have the correct credentials.
The project P1 is meant to be delivered to another company; let's call it C2.
C2 also have an Azure DevOps company website, containing some repos.
C2 wants to validate the development each day against its own Azure pipeline (naming convention, code coverage, etc.).
The easiest thing to do would be to mirror P1 from C1 to C2 and then work only in C2/P1. The problem is that access to C2 is forbidden outside of the company domain, and that most of the developer don't develop in C2 building.
We had the following idea:
- each day, on a developer computer who is in C2 building, a pull is performed on C1/P1;
- just after that, a push is performed from local to C2/P1.
Sadly, this approach only works if there are no merge conflit, if the developer computer is always up and running, etc.
Is there some kind of git approach that will allow C1/P1 to be completely copied each day to C2/P1?
Thanks.
回答1:
You can create another pipeline to run git commands to clone the C1/P1 and push to C2/P1. Please check below detailed steps:
1, create a new pipeline in C1/P1 to sync C2/P1 with C1/P1.(In classic UI Pipeline). On the pipeline edit page, Click Get source and Check Don't sync sources to skip cloning C1/P1 by agent job.
2, Add a powershell task to run below scripts. Below script will clone C1/P1 and then change the remote url to C2/P1, then push the code to C2/P1. You will need to use PAT to anthenticate. Check here to generate PAT with Code read and write scope
- powershell: |
git clone https://{PAT for C1/P1}@dev.azure.com/{org}/{proj}/_git/EmptyTestYaml
cd EmptyTestYaml #cd the code folder
git remote set-url origin https://{PAT for C2/P1}@dev.azure.com/{org}/{proj}/_git/CrossMicRepo2
git push -u origin --all -q
displayName: 'PowerShell Script'
3, Click the Triggers Tab to Enable continuous integration. So that with above steps. the C1/P1 will be automatically synced to C2/P1 when any changes committed to C1/P1.
Option:
If C2 does not have to have the source code in its C2/P1, for C1/P1 is open to all with correct credentials. C2 can just create its pipeline with the source code repo pointing to C1/P1. In this way, the C1/P1 source code doesnot have to be synced to C2/P1, and C2 can still validate the development each day against its own Azure pipeline.
Below is the detailed steps to configure the source repo of C2/P1 pipeline to C1/P1.
1, From the C2/P1 pipeline edit page, Click get Source and Choose Other Git, Click New service connection(Or add connection if not configured before).
2, In the prompted window, enter the azure repo url of C1/P1 and PAT for C1/P1.
3, Then Click the Triggers Tab to Enable continuous integration. Then when any changes commited to C1/P1, pipeline of C2/P1 will get triggered.
You can also add the service connection from the Project setting page of C2/P1. Check here for details
Hope above helps!
来源:https://stackoverflow.com/questions/60322953/git-periodically-replicate-a-repo-into-another-one-not-reachable-from-outside-t