【问题标题】:Check git log with shell script使用 shell 脚本检查 git 日志
【发布时间】:2016-11-15 00:13:03
【问题描述】:

简单的 shell 脚本问题。在 BB 中设置管道,我要移植的工作之一是通过一些 grunt 命令增加凉亭版本。我把它分解成单独的工作,这样它就不会自动运行,因为它会碰撞包,并提交回 repo。所以我想做的是当任务开始时,运行 git log 命令,检查最后的提交消息,如果它与预定义的消息匹配,然后退出。否则继续。如何检查最新的 git commit 消息并在 bash 中运行 if else check?

#! /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

【问题讨论】:

  • 问题是什么?
  • 如果我能够读取 git log last commit 消息并运行 if else bash 中的语句。我是,但我的 JavaScript 头脑需要更多地了解 shell 脚本。 :)

标签: git shell bitbucket-pipelines


【解决方案1】:

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

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

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

如果这不是您要问的,请实际提出一个问题,然后我们的贡献者就有了可以使用的上下文!

【讨论】:

  • 这是我最初的想法,也是我最初在 Bamboo 中处理它的方式。只要所有提交都通过 PR 合并,这应该基于功能分支/发布分支​​策略工作。我花了一段时间才把它改正,但多亏了我上面的解决方案中的一个帖子,它起作用了。如果 else 语句返回 true,我现在唯一遇到的问题是让另一个 shell 脚本从第一个内部启动。
【解决方案2】:

找到了似乎满足我对管道的需求的解决方案,尽管如果已经收到消息,我需要设置不同的 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-29
    • 1970-01-01
    • 2018-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-05
    相关资源
    最近更新 更多