zoukankan      html  css  js  c++  java
  • Github和Azure DevOps的代码同步

    【前言】
    Github和Azure DevOps都提供了Git代码库功能,那么有没有办法将两边的代码库进行同步呢,答案是肯定的。
    这里的操作我都是用Azure DevOps的Pipelines功能来完成的,当然用Github的Actions应该也能达到类似的效果,其他小伙伴们不妨尝试一下。
     
    【从Azure DevOps到Github】
    由于我个人平时习惯于用Azure DevOps存放代码,所以这里就先讲如何将你再Azure DevOps提交的代码同步到Github仓库
    首先我们创建一个新的Pipeline,起名叫“Sync From Azure DevOps to GitHub”
     
    因为这里是要同步Azure DevOps的代码,所以Connect下选择Azure Repo Git,不熟悉YAML的同学可以点击下方的Use the classic editor,就会变成一个图形化的设置界面
    第二步,选择你的代码库,这里我选的是Ant-Design-Blazor

    第三步,选择模板,这里图片截不下了,往下拉选择Starter pipeline

    YAML内容如下,注意username里的‘@’要替换成‘%40’

    关于如何编写Pipeline YAML可以参考微软的文档 https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema
     1 # Starter pipeline
     2 # Start with a minimal pipeline that you can customize to build and deploy your code.
     3 # Add steps that build, run tests, deploy, and more:
     4 # https://aka.ms/yaml
     5 variables: # pipeline-level 
     6   branch: 'azure_branch'
     7  
     8 trigger:
     9 - master
    10 pool:
    11   vmImage: 'ubuntu-latest'
    12 steps:
    13 - script: |
    14    git remote add github https://<username>:<password>@github.com/Brian-Ding/ant-design-blazor.git
    15    git checkout -b $(branch)
    16    git push -u github $(branch)
    17    
    18    
    19   displayName: 'Command Line Script'

    【从Github到Azure DevOps】

    前面的操作都和之前类似,只是记得Connect那一步要选择Github

     1 steps:
     2 - script: |
     3    mkdir sync
     4    cd sync
     5    git clone https://github.com/xxx/xxx.git
     6    cd <github project>
     7    git remote add azure https://<Azure DevOps Organization>:<token>@dev.azure.com/<Azure DevOps Organization>/<project>/_git/<repo.git> 8    
     9    git branch -D $(branch)
    10    git checkout -b $(branch)
    11        
    12    git push -d azure $(branch)
    13    git push -u azure $(branch) --force
    14   displayName: 'Command Line Script'
     
  • 相关阅读:
    php对接网易云信视频直播
    python基础--1.数据操作
    pytest自动化7:assert断言
    pytest自动化6:pytest.mark.parametrize装饰器--测试用例参数化
    pytest自动化5:pytest-html插件--生成html报告
    pytest自动化4:fixture之yield实现teardown
    pytest自动化3:fixture之conftest.py实现setup
    pytest自动化2:测试用例setup和teardown
    pytest自动化1:兼容unittest代码实例
    排序
  • 原文地址:https://www.cnblogs.com/brian-ding/p/13217543.html
Copyright © 2011-2022 走看看