使用Jenkins时,如果GIT_COMMIT无变化,跳过构建

原创
2016/02/04 10:12
阅读数 1W
使用Jenkins时,如果GIT_COMMIT无变化,跳过构建

使用插件: conditional-buildstep
A buildstep wrapping any number of other buildsteps, controlling their execution based on a defined condition (e.g. BuildParameter).

如下图所示,如果环境变量GIT_PREVIOUS_SUCCESSFUL_COMMIT不存在,或者GIT_COMMIT和GIT_PREVIOUS_SUCCESSFUL_COMMIT不同,才会执行构建



上图中脚本如下:
#!/bin/bash
if [ ! $GIT_PREVIOUS_SUCCESSFUL_COMMIT ];then
    echo "GIT_PREVIOUS_SUCCESSFUL_COMMIT is not exists."
    exit 0
else
    echo "GIT_COMMIT=[$GIT_COMMIT],GIT_PREVIOUS_SUCCESSFUL_COMMIT=[$GIT_PREVIOUS_SUCCESSFUL_COMMIT]"
    if [ $GIT_PREVIOUS_SUCCESSFUL_COMMIT == $GIT_COMMIT ];then
        echo "GIT_COMMIT is equals to GIT_PREVIOUS_SUCCESSFUL_COMMIT,skip build."
        exit -1
    else
    	echo "GIT_COMMIT is not equals to GIT_PREVIOUS_SUCCESSFUL_COMMIT"
        exit 0
    fi
fi




展开阅读全文
打赏
2
18 收藏
分享
加载中
更多评论
打赏
0 评论
18 收藏
2
分享
返回顶部
顶部