Jenkins 管道、bitbucket 钩子和 maven 发布插件无限循环
Jenkins pipeline, bitbucket hook and maven release plugin infinite loop
我还没有找到任何关于这方面的信息,所以我希望你们能在这方面帮助我
我有一个托管在 bitbucket 中的 Maven 项目,它有一个指向 someurl/bitbucket-hook/ 的 BitBucket WebHook,这个钩子触发了我的项目的构建,该项目由具有以下结构的管道定义:
node {
stage 'Checkout'
git url: 'https:...'
def mvnHome = tool 'M3'
#Various stages here
...
stage 'Release'
sh "${mvnHome}/bin/mvn -B clean install release:prepare release:perform release:clean"
}
问题是 maven release plugin push changes to BitBucket,这又触发了 jenkins 脚本,造成无限循环的构建,有没有办法避免这种情况?
我尝试在 Jenkins 中设置静默期但没有成功
从我的角度来看,您应该有特定的构建和发布作业,并且应该手动触发发布作业。无论如何,如果有某种原因让他们参与工作,您可以检查最后一次提交的消息:
node {
git 'https...'
sh 'git log -1 > GIT_LOG'
git_log = readFile 'GIT_LOG'
if (git_log.contains('[maven-release-plugin]')) {
currentBuild.result = 'ABORTED'
return
}
... // continue with release or whatever
}
A New Way to Do Continuous Delivery with Maven and Jenkins Pipeline文章方法解决死循环:
Use the Maven release plugin to prepare a release with
pushChanges=false (we are not going to push the release commits back
to master) and preparationGoals=initialize (we don't care if the tag
is bad as we will only push tags that are good)
sh "${mvnHome}/bin/mvn -DreleaseVersion=${version} -DdevelopmentVersion=${pom.version} -DpushChanges=false -DlocalCheckout=true -DpreparationGoals=initialize release:prepare release:perform -B"
另一种解决方案是更改 git 挂钩 (post-receive) 并添加类似于此脚本的条件卷曲:
#!/bin/bash
git_log=$(git log --branches -1)
if ! [[ $git_log =~ .*maven-release-plugin.* ]] ;
then
curl http://buildserver:8080/git/notifyCommit?url=ssh://git@server/projects/name.git;
fi
我还没有找到任何关于这方面的信息,所以我希望你们能在这方面帮助我
我有一个托管在 bitbucket 中的 Maven 项目,它有一个指向 someurl/bitbucket-hook/ 的 BitBucket WebHook,这个钩子触发了我的项目的构建,该项目由具有以下结构的管道定义:
node {
stage 'Checkout'
git url: 'https:...'
def mvnHome = tool 'M3'
#Various stages here
...
stage 'Release'
sh "${mvnHome}/bin/mvn -B clean install release:prepare release:perform release:clean"
}
问题是 maven release plugin push changes to BitBucket,这又触发了 jenkins 脚本,造成无限循环的构建,有没有办法避免这种情况?
我尝试在 Jenkins 中设置静默期但没有成功
从我的角度来看,您应该有特定的构建和发布作业,并且应该手动触发发布作业。无论如何,如果有某种原因让他们参与工作,您可以检查最后一次提交的消息:
node {
git 'https...'
sh 'git log -1 > GIT_LOG'
git_log = readFile 'GIT_LOG'
if (git_log.contains('[maven-release-plugin]')) {
currentBuild.result = 'ABORTED'
return
}
... // continue with release or whatever
}
A New Way to Do Continuous Delivery with Maven and Jenkins Pipeline文章方法解决死循环:
Use the Maven release plugin to prepare a release with pushChanges=false (we are not going to push the release commits back to master) and preparationGoals=initialize (we don't care if the tag is bad as we will only push tags that are good)
sh "${mvnHome}/bin/mvn -DreleaseVersion=${version} -DdevelopmentVersion=${pom.version} -DpushChanges=false -DlocalCheckout=true -DpreparationGoals=initialize release:prepare release:perform -B"
另一种解决方案是更改 git 挂钩 (post-receive) 并添加类似于此脚本的条件卷曲:
#!/bin/bash
git_log=$(git log --branches -1)
if ! [[ $git_log =~ .*maven-release-plugin.* ]] ;
then
curl http://buildserver:8080/git/notifyCommit?url=ssh://git@server/projects/name.git;
fi