同步两个git仓库Jenkins Pipeline [英] Sync two git repositories Jenkins Pipeline

查看:875
本文介绍了同步两个git仓库Jenkins Pipeline的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次构建一个版本时,我都希望同步两个存储库,我已经看到了此脚本,但是我也不知道如何使用凭据设置远程分支.

I want to syncronize two repositories each time a build is been made, I have seen this script but I don't know how to set the remote branch with credentials too.

# clone the reposotory
git clone --bare $ORIGIN_URL

# add a remote repository
cd $REPO_NAME
git remote add --mirror=fetch repo1 $REPO1_URL

# update the local copy from the first repository
git fetch origin --tags

# update the local copy with the second repository
git fetch repo1 --tags

# sync back the 2 repositories
git push origin --all
git push origin --tags
git push repo1 --all
git push repo1 --tags

管道:

node('centos-small') {
    sh 'git config --global user.email "jenkins@xxx.com"'
    sh 'git config --global user.name "ci-bot"'
    git credentialsId: 'JenkinsGit', url: 'git url'
}

我不知道如何设置凭据以将更改推送到远程存储库. git push repo1-全部 git push repo1-标签

I don't know how to set the credentials to push changes to remote repo. git push repo1 --all git push repo1 --tags

推荐答案

当某些东西(通过webhook或类似的东西)被推送到第一个仓库时,应该触发该事件

This should be triggered when something is pushed to the first repo (via webhook or similar)

node('centos-small') {
    stage('Set Git Config'){
        sh 'git config --global user.email "test@test.com"'
        sh 'git config --global user.name "ci-bot"'
        sh 'git config --global credential.helper cache'
        sh "git config --global credential.helper 'cache --timeout=3600'"
    }
    stage('Set Git Credentials'){
        git credentialsId: 'JenkinsGit', url: '${TFS_REPO}'
        git credentialsId: 'Second', url: '${SECOND_REPO}'
    }

    stage('Syncronize TFS-SECOND'){
        sh 'git clone --bare ${TFS_REPO} tfs'
        dir("tfs") {
            //add a remote repository
            sh 'git remote add --mirror=fetch second ${SECOND_REPO}'
            // update the local copy from the first repository
            sh 'git fetch origin --tags'

            // update the local copy with the second repository
            sh 'git fetch second --tags'

            // sync back the second repository
            sh 'git push second --all'
            sh 'git push second --tags'
        }
    }
}

这篇关于同步两个git仓库Jenkins Pipeline的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆