如何在 gitlab 管道中使用来自另一个存储库的 bash 脚本?

问题描述 投票:0回答:1

我在 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

bash git gitlab continuous-integration pipeline
1个回答
0
投票

这是一种方法做到这一点:

  1. 克隆项目 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

  2. 为您的脚本添加

    执行权限(您可能不需要这个) chmod +x script1.sh script2.sh script3.sh

  3. 执行脚本
  4. ./script1.sh ./script2.sh ./script3.sh

    
    
  5. 以上所有内容结合在一起,应该是这样的:

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

© www.soinside.com 2019 - 2024. All rights reserved.