如果提交消息包含[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..."
}
}