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

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

使用插件: conditional-buildstep
A buildstep wrapping any number of other buildsteps, controlling their execution based on a defined condition (e.g. BuildParameter).
wiki: https://wiki.jenkins-ci.org/display/JENKINS/Conditional+BuildStep+Plugin

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

使用Jenkins时,如果GIT_COMMIT无变化,跳过构建_第1张图片


上图中脚本如下:
#!/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




你可能感兴趣的:(git,Jenkins)