同步两个git存储库Jenkins管道

时间:2017-10-02 17:38:10

标签: 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

管道:

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 --all git push repo1 --tags

1 个答案:

答案 0 :(得分:4)

当某些东西被推送到第一个仓库时(通过webhook或类似的)

,这应该被触发
//checking even and odd
$num =14;

$even = ($num % 2 == 0);
$odd = ($num % 2 != 0);

if($even){
    echo "Number is even.";
} else {
    echo "Number is odd.";
}
相关问题