使用 shell 脚本检查 git 日志

Check git log with shell script

简单的shell脚本问题。在 BB 中设置管道,我正在移植的工作之一是通过一些 g运行t 命令增加一个 bower 版本。我把它分解成单独的作业,这样它就不会自动 运行 因为它会影响包,并提交回回购协议。所以我想做的是当任务开始时,运行 一个 git 日志命令,检查最后的提交消息,如果它与预定义的消息匹配,那么就退出。否则继续。如何检查最新的 git 提交消息和 运行 if else 检查 bash?

#! /bin/bash

git log -1

if git log -1 === "pre-defined message";
  then
    echo "already pushed and bumped exiting"
    exit 1
  else
    echo "not bumped -- continuing job"
    ./setup-git.sh
fi

我认为您正在尝试做的是忽略导致构建或其他步骤的某些提交....虽然这在手动构建环境中可能工作正常,但标准构建工具会出现问题。

我在 Jenkins 中遇到过这个问题,作为构建的一部分使用和修改的支持文件会在提交回存储库时触发构建,从而导致永无止境的构建周期。

我的解决方案是将 repo 分成一个目录中的源代码,另一个目录中的支持文件,然后为 Jenkins 添加一个排除区域,这样构建生成的提交不会导致下一次轮询执行任何操作(因为提交的文件与正在构建的实际项目无关)。有点迟钝,但似乎有效。

如果这不是您要问的,请实际提出问题,然后我们的贡献者就有了工作背景!

虽然我需要设置不同的 shell 脚本以防止 运行 如果已收到消息,则 npm 不会安装

找到了似乎可以满足我对管道的需求的解决方案:

#! /bin/bash

MESSAGE=$(git log -1 HEAD --pretty=format:%s)

if [[ "$MESSAGE" == "This goes into next release" ]]; then
    echo "already pushed run grunt and exit"
    grunt build
    echo "nothing to see here -- move along"
else
    echo "not bumped -- continuing job"
    git config --global user.email "user@user.com"
    git config --global user.name "Blah Blah"
    git remote set-url origin https://user:password@bitbucket.org/myawesomegitrepo.git
    grunt releaseme
    git config --global push.default matching
    git commit dist/destro -m "This goes into next release"
    git push --tags
fi

感谢 James Nine 在这个话题上的回答:How to capture a git commit message and run an action