gpt4 book ai didi

git - 如果仅更改特定文件,则触发 jenkins 构建

转载 作者:太空狗 更新时间:2023-10-29 14:28:58 26 4
gpt4 key购买 nike

我在 GIT 中有我的代码库。代码库中有 5 个文件,即

  • 文件1
  • 文件2
  • 文件3
  • 文件4
  • 文件5

我只想在文件 2 更改时触发 jenkins 构建。请注意,触发构建后它应该 pull 整个代码库。

我尝试使用 poll SCM,但问题是如果存储库中的任何文件发生更改,构建就会被触发。我只想在文件 2 更改时触发它。

这可能吗?

最佳答案

这是我的做法。

  1. 将您的 Jenkins 作业配置为 Trigger builds remotely .

    这会启用 JENKINS_URL/job/MYJOB/build?token=TOKEN_NAME 形式的构建触发器 URL .您必须自己指定 token 名称。

  2. 在您的存储库上配置一个 git post-receive Hook 以调用该触发器。

    钩子(Hook)的脚本通常在.git/hooks/post-receive下. post-receive hook 在整个过程完成后运行,可用于更新其他服务或通知用户。

    post-receive hook 从 stdin 获取参数,格式为 <oldrev> <newrev> <refname> .

    您可以从新的 HEAD 提交中检索文件列表,然后仅在包含 File2 时才继续下一步.像这样(未经测试):

    #!/bin/bash
    while read oldrev newrev refname
    do
    # list of changed files for a commit
    filelist=$(git diff-tree --no-commit-id --name-only -r $newrev)
    if [[ $filelist == *"File2"* ]]; then
    # call the URL according to your build trigger config
    fi
    done

More details on git hooks.

关于git - 如果仅更改特定文件,则触发 jenkins 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47152744/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com