问题描述
我只需要将我的Bitbucket存储库中的一个分支暴露给新的gitlab存储库.我的学生正在使用gitlab.com世界,而我的所有教学内容都存储在bitbucket存储库中.而且我想为特定的类提供特定的分支.
I need to only expose one branch from my bitbucket repo to a new gitlab repo. My students are using the gitlab.com world and I have all my teaching stuff in bitbucket repo's. And I would like to have specific branches for specific classes.
例如:
Bitbucket具有回购APCSA与分支机构:掌握每1每2每3开发
Bitbucket has the repo APCSAwith the branches:masterper1per2per3dev
我想在不同的gitlab组下在gitlab上设置不同的仓库.
I want to have different repo's setup on gitlab under different gitlab groups.
因此,在一个小组中,我希望让他们仅看到:
So under one group I'd like to have them see only:
APCSA:per1分支(我很想弄清楚该如何镜像)
APCSA:per1 branch (and I'd love to figure out how to mirror this)
我已经尝试了很多组合镜像,但是它总是镜像整个仓库,所有分支.
I've tried lots of combo's of mirroring but it always mirrors the entire repo, all branches.
推荐答案
您可以创建GitLab CI/CD 管道以克隆或提取单个分支.您的管道可以在不同的分支上运行,以避免冲突等.
You can create a GitLab CI/CD pipeline to clone, or pull, a single branch. Your pipeline can run on a different branch, in order to avoid conflicts and such.
使用网络用户界面
- 创建一个名为
mirror
的新分支 - 在设置"中,填充CI/CD变量:上游,要镜像的分支和您的回购地址
- 在
mirror
分支中创建一个名为.gitlab-ci.yml
的新文件- 将在每次提交时触发管道,您将能够检查其是否正常工作
- create a new branch called
mirror
- in Settings, populate CI/CD variables: your upstream, the branch to mirror, and your repo address
- create a new file called
.gitlab-ci.yml
in themirror
branch- the pipeline will be trigged upon (each) commit, and you'll be able to check if it's working
这是我的
.gitlab-ci.yml
,用于镜像上游分支:This is my
.gitlab-ci.yml
to mirror an upstream branch:job: script: - git remote show writable || git remote add writable $WRITABLE_URL - git checkout $UPSTREAM_BRANCH || git checkout -b $UPSTREAM_BRANCH - git pull $UPSTREAM_URL $UPSTREAM_BRANCH - git push writable $UPSTREAM_BRANCH only: - mirror
变量为:
-
WRITABLE_URL
=目标,即:'git@gitlab.myplace.local:upstream/ansible.git' -
UPSTREAM_URL
=来源,即:' https://github.com/ansible/ansible.git ' -
UPSTREAM_BRANCH
=即:'stable-2.8'
WRITABLE_URL
= destination, ie: 'git@gitlab.myplace.local:upstream/ansible.git'UPSTREAM_URL
= origin, ie: 'https://github.com/ansible/ansible.git'UPSTREAM_BRANCH
= ie: 'stable-2.8'
如果需要,您将需要使用命令行来安装 gitlab-runner 还没有.您还需要创建一个部署密钥(设置/存储库),以允许
push
起作用(或使用部署令牌,但是在免费计划中没有针对部署令牌的写访问权限.You will need to use the command line to install gitlab-runner, if you don't have one already. You will also need to create a deploy key (Settings / Repository) in order to allow
push
to work (or use deploy token, but write access is not available in the free plan for deploy tokens).这篇关于需要设置一个仅暴露一个分支的位桶回购的gitlab镜像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!