需求分析

在jenkins中没有找到构建前插件,每次构建时间很长,希望可以实现判断代码是否更新,如果没更细则停止构建步骤。

实现步骤

在构建时执行shell命令,而jenkins提供的的环境变量可以实现此判断 https://wiki.jenkins.io/display/JENKINS/Conditional+BuildStep+Plugin

GIT_COMMIT
    The commit hash being checked out.
GIT_PREVIOUS_COMMIT
    The hash of the commit last built on this branch, if any.
GIT_PREVIOUS_SUCCESSFUL_COMMIT
    The hash of the commit last successfully built on this branch, if any.

GIT_COMMIT 当前拉取版本的commit id
GIT_PREVIOUS_COMMIT 最后在此分支上构建的 commit id
GIT_PREVIOUS_SUCCESSFUL_COMMIT 最后在此分支上成功构建的 commit id号

#!/bin/bash

if [ $GIT_PREVIOUS_SUCCESSFUL_COMMIT == $GIT_COMMIT ];then
  echo "no change,skip build"
  exit 0
else
  echo "git pull commmit id not equals to current commit id trigger build"
fi

注意,不能使用-eq 只能使用==
jenkins检查代码,如没更新停止构建步骤

提交新版本后,构建提示如下:

jenkins检查代码,如没更新停止构建步骤

$ git show|head -1
commit 27617e680d2e6bf00062700623792aef63926edd

在jenkins中执行构建
jenkins检查代码,如没更新停止构建步骤

相关文章:

  • 2021-10-22
  • 2021-12-28
  • 2021-08-18
  • 2022-01-14
  • 2022-02-23
  • 2021-09-11
猜你喜欢
  • 2021-09-23
  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
  • 2021-09-19
  • 2021-09-26
相关资源
相似解决方案