使用 Jenkins 将一个 git 存储库镜像到另一个存储库

时间:2021-06-15 14:11:06

标签: git jenkins jenkins-pipeline mirror multibranch-pipeline

TL;DR:如何使用 Jenkins 多分支管道将一个存储库镜像到另一个存储库?

我在 Jenkins 中有一个多分支管道,我用它来将代码从一个存储库(防火墙后面)提取到开放互联网上的 Azure 存储库。

截至目前,我只推送了 master 分支,因为我认为 Azure Repos 中不需要其他分支。但是,现在我的一位同事希望包括其他分支。 我当前的管道首先创建一个新的 git remote,指向 Azure Repos,稍后它会与 git push 一起使用。

当前管道的示例:

pipeline {
    agent any
    stages {
        stage('Setup') {
            steps {
                sh 'git remote add azure https://{{token}}@{{AzureRepoUrl}}'
            }
        }
        
        stage('Push master') {
            when {
                branch 'master'
                beforeAgent true
            }
            steps {
                sh 'git push azure HEAD:refs/heads/${BRANCH_NAME}'
            }
        }
    }
}

我现在已经可以看到,当包含所有分支时,这将不起作用,因为在源远程中删除时不会清理分支。

我曾考虑使用 push --mirror,但没有成功,因为它最终使用了 Jenkins 本地存储库,因为多分支管道结帐不使用 --mirror。

关于如何将我的 origin 遥控器镜像到我的 azure 遥控器的任何建议?

0 个答案:

没有答案
相关问题