简体   繁体   English

GIT 交叉检查和 jenkins 管道的依赖性检查

[英]GIT cross checkout and dependency check for jenkins pipeline

I have following git project structure:我有以下 git 项目结构:

MAIN_PRJ
  SUB_MODULE1
  SUB_MODULE2
     SUB_MODULE2_1
  SUB_MODULE3
     SUB_MODULE3_1
         SUBMODULE_3_1_1

As part of my jenkins job trigger, the trigger message that passed contains fetch commands for curtain sub-modules, passed as a string.作为我的 jenkins 作业触发器的一部分,传递的触发器消息包含窗帘子模块的获取命令,作为字符串传递。 For example:例如:

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

We use those for cross dependency checks.我们使用它们进行交叉依赖检查。 I am looking for a way to make all those "fetches" recursively.我正在寻找一种方法来递归地进行所有这些“获取”。

One of the direction -方向之一——

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

  2. get the remote from it从中获取遥控器

  3. compare remote path to fetch path比较远程路径和获取路径

  4. if true execute the fetch command如果为真,执行 fetch 命令

git remote -v Command returns the origin for fetch and push, Is there a way to get only one of them? git remote -v命令返回获取和推送的来源,有没有办法只获取其中一个? Is there a way to store this remote value as a parameter?有没有办法将此远程值存储为参数? The path during the recursive run stored as pwd parameter.递归运行期间的路径存储为 pwd 参数。

In my vision it will look like that:在我看来,它看起来像这样:

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

Any other Ideas?还有其他想法吗?

Update: So far I managed to combine following command that partly works:更新:到目前为止,我设法结合了以下部分有效的命令:

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'

But I am getting an error, for explanation let assume that fetch_remote="http://git_remote/SUB_MODULE2_1"但我收到一个错误,为了解释让我们假设 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

Found solution that work for me:找到适合我的解决方案:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM