使用shell脚本检查git log

时间:2016-11-15 00:13:04

标签: git shell bitbucket-pipelines

简单的shell脚本问题。在BB中设置管道以及我移植的其中一个作业是通过一些grunt命令增加一个bower版本。我将它分解为单独的作业,因此它不会自动运行,因为它会破坏程序包,并返回到repo。所以我要做的是当任务开始时,运行git log命令,检查最后一次提交消息,如果它与预定义的消息匹配,那么就退出。否则继续。如何查看最新的git commit消息并在bash中运行if else check?

$watch

2 个答案:

答案 0 :(得分:1)

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

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

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

如果这不是你问的问题,实际上问一个问题然后我们的贡献者有一个上下文可以使用!

答案 1 :(得分: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

相关问题