我在 Gitlab 中有两个项目。在项目 A 中,有 Bash 脚本(全部位于单个文件夹中)。项目 B 包含一条管道。我怎样才能实现这个?我已经尝试过使用 Git 子模块,但是当我尝试初始化和更新管道中的子模块时,出现错误:
Submodule 'a' (https://gitlab-ss.intranet.x.com/a) registered for path 'b'
Cloning into 'a/b'...
fatal: could not read Username for 'https://gitlab-ss.intranet.x.com': No such device or address
fatal: clone of 'https://gitlab-ss.intranet.x.com/b' into submodule path 'a/b' failed
Failed to clone 'b'.
我把真实的项目名称替换成了a、b、x
这是一种方法做到这一点:
仅克隆项目 A中的文件夹(包含脚本),以使用预定义变量 CI_JOB_TOKEN
在项目 B
的管道中使用它。 有关预定义 CI/CD 变量的更多详细信息,请参阅此处。
script:
- |
git clone --depth 1 --no-checkout https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab-ss.intranet.x.com/namespace/project_name
cd project_name
git sparse-checkout set --no-cone scripts_folder
git checkout
cd scripts_folder
ls -a
./script1.sh
./script2.sh
./script3.sh
script:
- |
git clone --depth 1 --no-checkout https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab-ss.intranet.x.com/namespace/project_name
cd project_name
git sparse-checkout set --no-cone scripts_folder
git checkout
cd scripts_folder
ls -a
chmod +x script1.sh script2.sh script3.sh
./script1.sh
./script2.sh
./script3.sh