【问题标题】:GIT cross checkout and dependency check for jenkins pipeline詹金斯管道的 GIT 交叉签出和依赖项检查
【发布时间】:2020-09-10 22:40:42
【问题描述】:

我有以下 git 项目结构:

MAIN_PRJ
  SUB_MODULE1
  SUB_MODULE2
     SUB_MODULE2_1
  SUB_MODULE3
     SUB_MODULE3_1
         SUBMODULE_3_1_1

作为我的詹金斯作业触发器的一部分,传递的触发器消息包含窗帘子模块的获取命令,作为字符串传递。例如:

git fetch https://git.server/SUB_MODULE1 hash_commit;git fetch https://git.server/SUB_MODULE2_1 hash_commit;git fetch https://git.server/SUB_MODULE3_1_1 hash_commit

我们使用它们进行交叉依赖检查。 我正在寻找一种方法来递归地进行所有这些“获取”。

方向之一——

  1. 运行git submodule foreach --recursive 'git remote -v'command

  2. 从中获取遥控器

  3. 比较远程路径和获取路径

  4. 如果为真则执行获取命令

git remote -v 命令返回 fetch 和 push 的来源,有没有办法只获取其中一个?有没有办法将此远程值存储为参数?递归运行期间的路径存储为 pwd 参数。

在我看来,它会是这样的:

foreach fetch_remote in fetchlist:
    git submodule foreach --recursive 'git remote -v;if [$origin==$fetch_remote] then fetch_command fi' 

还有其他想法吗?

更新: 到目前为止,我设法结合了以下部分有效的命令:

foreach fetch_remote in fetchlist:
   git submodule foreach --recursive 'sub_remote=$(git remote get-url origin);if[$sub_remote==$fetch_remote];then $fetch_command; fi'

但我收到一个错误,为了解释,假设 fetch_remote="http://git_remote/SUB_MODULE2_1"

/usr/lib/git-core/git-submodule: 1: eval: [http://git_remote/SUB_MODULE2_1==http://git_remote/SUB_MODULE2_1]: not found

【问题讨论】:

  • 试试空格和单个=:if [ $origin = $fetch_remote ]; then
  • 试过这个:' git submodule foreach --recursive 'sub_remote=$(git remote get-url origin);if [ $sub_remote=$fetch_remote ];then $fetch_command; fi' ' 但是现在总是打印 YES - 避免 if 条件

标签: git jenkins git-bash


【解决方案1】:

找到适合我的解决方案:

foreach fetch_remote in fetchlist:
    git submodule foreach --recursive 'if [ "$(git remote get-url origin)"  = "$fetch_remote" ]; then fetch_command; fi'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-09
    • 2018-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多