Mik*_*hez 3 git jenkins jenkins-pipeline
我想在每次构建时同步两个存储库,我看过这个脚本,但我也不知道如何使用凭据设置远程分支。
# 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
Run Code Online (Sandbox Code Playgroud)
管道:
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'
}
Run Code Online (Sandbox Code Playgroud)
我不知道如何设置凭据以将更改推送到远程存储库。git push repo1 --all git push repo1 --tags
这应该在某些东西被推送到第一个 repo 时触发(通过 webhook 或类似的)
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'
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4749 次 |
| 最近记录: |