使用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不同,才会执行构建
上图中脚本如下:
#!/bin/bashif [ ! $GIT_PREVIOUS_SUCCESSFUL_COMMIT ];then echo "GIT_PREVIOUS_SUCCESSFUL_COMMIT is not exists." exit 0else 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 fifi
看完上述内容,你们掌握使用Jenkins时如果GIT_COMMIT无变化该怎么办的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注编程网行业资讯频道,感谢各位的阅读!