Sync two git repositories Jenkins Pipeline

空扰寡人 提交于 2019-12-04 15:25:01

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'
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!