首页 > 解决方案 > 从 Gerrit 到 Bitbucket 的远程分支

问题描述

最近我们已经从使用 gerrit 转移到了 Bitbucket。Gerrit 中很少有远程分支需要同步到 Bitbucket。由于分支机构的数量很多,因此需要自动化。任何指示都会有所帮助

标签: bitbucketgerrit

解决方案


示例 jenkinsfile 将远程分支从 gerrit 推送到 Bitbucket -


// ssh credentials
def credentials_id = 'XXXXXXXXXXXXXXX-UUUUUU-III'

pipeline {
  options {
    buildDiscarder(logRotator(numToKeepStr: '600'))
    disableConcurrentBuilds()
  }

  agent { node { label 'Master' } }

  stages {
    stage('try') {
      steps {
        checkout(
          [
            $class: 'GitSCM',
            branches: [
              [
                name: '${gerrit-branch-name}'
              ]
            ],
            doGenerateSubmoduleConfigurations: false,
            extensions: [
              [
                $class: 'CheckoutOption',
                timeout: 20
              ],
              [ $class: 'LocalBranch',
                localBranch: '${local-branch-name-bitbucket}'
              ]
            ],
            gitTool: 'Default',
            submoduleCfg: [],
            userRemoteConfigs: [
              [
                credentialsId: credentials_id,
                name: 'gerrit',
                url: '${gerrit-URL}'
              ],
              [
                credentialsId: credentials_id,
                name: 'bitbucket',
                url: '${bitbucket-URL}'
              ]
            ]
          ]
        )
      }
    }
    stage('Push updates of branch to Bitbucket') {
      steps {
          bat 'git push --tags bitbucket ${gerrit-branch-name}:refs/heads/${local-branch-name-bitbucket}`enter code here`'
      }
    }    
  }
}

推荐阅读