Jenkins pipeline, bitbucket hook and maven release plugin infinite loop

可紊 提交于 2019-12-06 07:15:57

From my perspective you should have specific jobs for build and release, and the release job should be triggered manually. Anyway, if there is some reason to have them in the job you can check for the message of the last commit:

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 article approach solves the infinite loop:

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"

Another solution can be to change the git hook (post-receive) and add a conditional curl similar to this script:

#!/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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!