我还没有找到关于此的任何信息,所以我希望你们可以帮助我这个
我在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发布插件将更改推送到BitBucket,这会再次触发jenkins脚本,构建无限循环,是否有办法防止这种情况?
我试过在詹金斯安静的时期没有成功
答案 0 :(得分:2)
从我的角度来看,您应该拥有构建和发布的特定作业,并且应该手动触发发布作业。无论如何,如果有一些理由让他们在工作中你可以检查上次提交的消息:
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
}
答案 1 :(得分:0)
A New Way to Do Continuous Delivery with Maven and Jenkins Pipeline文章方法解决了无限循环:
使用Maven版本插件准备一个版本 pushChanges = false(我们不会推迟发布提交 掌握)和prepareGoals = initialize(我们不关心标签 是坏事,因为我们只会推送好的标签
sh "${mvnHome}/bin/mvn -DreleaseVersion=${version} -DdevelopmentVersion=${pom.version} -DpushChanges=false -DlocalCheckout=true -DpreparationGoals=initialize release:prepare release:perform -B"
答案 2 :(得分:0)
另一种解决方案可以是更改git hook(post-receive)并添加类似于此脚本的条件curl:
#!/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