0

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

2 回答 2

1

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

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

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

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

于 2016-11-15T02:24:09.400 回答
1

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

于 2016-11-15T06:15:51.157 回答