如果提交消息包含[ci skip],如何获取git最新提交消息并防止jenkins构建? [英] How to get the git latest commit message and prevent the jenkins build if the commit message contains [ci skip]?

查看:264
本文介绍了如果提交消息包含[ci skip],如何获取git最新提交消息并防止jenkins构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在jenkinsfile中获取git commit消息,并阻止基于提交消息的构建.

I tried to get the git commit message in jenkinsfile and prevent the build based on commit message.

env.GIT_COMMIT 不会在jenkinsfile中返回提交详细信息.

env.GIT_COMMIT doesn't return the commit details in jenkinsfile.

如果提交消息中包含[ci skip],如何获取git最新的提交消息并阻止jenkins构建?

How to get the git latest commit message and prevent the jenkins build if the commit message contains [ci skip] in it?

推荐答案

在最后一个git日志中提供[ci skip]时,构建将通过,但不会运行实际的构建代码(替换第一个echo语句) )

The build will pass when [ci skip] is provided in the last git log, but will not run the actual build code (the replacement to the first echo statement)

node {
  checkout scm
  result = sh (script: "git log -1 | grep '\\[ci skip\\]'", returnStatus: true) 
  if (result != 0) {
    echo "performing build..."
  } else {
    echo "not running..."
  }
}

这篇关于如果提交消息包含[ci skip],如何获取git最新提交消息并防止jenkins构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆