At my workplace, we use a monthly release branch that's shared across several developers.
Gradle version is 2.14.1
We manually trigger the code build and release (task) using Jenkins (which is effective running - gradle clean compileJava release)
The whole process takes about 30-40 minutes, basically compiling, generating the artifacts, running Junit tests and uploading the artifacts to the Artifactory.
Eventually it comes to the step of tagging and pushing the version number: preTagCommit, which tries to update the gradle.properties and bumps up the version number to it and commits and pushes.
At this point, if there have been no commits on the branch for the last 30-40 minutes (Since the build was manually triggered), the release works successfully.
The moment there is even a single commit between the whole process it fails with error: Execution failed for task ':preTagCommit'.
*
error: failed to push some refs to 'xxx.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
*
I tried several hacks and searched the documentation but not leading to any proper solution yet.
This is how my release step looks like:
***
release {
project.setProperty("gradle.release.useAutomaticVersion", "true");
newVersionCommitMessage = "Re-snapshoted project to version "
preTagCommitMessage = "Preparing version for release "
tagCommitMessage = "Tagging Release "
tagPrefix = "calypso"
requireBranch = ""
// Sometimes the plugin trips over its own feet with modifying the gradle.properties
// then complaining it has changed.
failOnCommitNeeded = false
pushToCurrentBranch = true
}
***
Apologies if this has been asked previously, all the solution I found was general approach to git rather than from someone using Gradle-Release-Plugin with git.
Any response will be greatly appreciated.
I believe the flag you're looking for is mentioned in the GitHub page of the plugin:
Edit
It seems that the above flag does not work for some reason. Yet, there is another way to accomplish this, and that is to add a force push option to the
git
option of therelease
extension (what a mouthful to say).This will basically force-overwrite the branch (see problem analysis below) unless the server on which the repository is hosted, is tuned to reject such forced pushes. In that case, there is really no option you can pass here that will help.
Problem analysis
As I said in my last comment below, the part that fails is when the extension runs the
preTagCommit
task, and then tries to push this commit to the upstream branch (master
for example). You can see this push command right here.Well of course this will fail if someone else already pushed a commit to that branch.
Now an easier way to fix this would have been if the plugin authors gave us the ability to say
Don't push preTag commits to upstream
or
Push preTagCommits to a branch named foo
Unfortunately they haven't given us this option (atleast from what I've gathered so far). So I have come up with some hacky solutions to circumvent this.
Solutions/Hacks
Specify pushToBranchPrefixCreate a tagged branchThis is another option that can be passed to thegit
object which causes all pushes it does to be done to a specific branch with a given prefix rather than the current branch:For example:
Replace
v1.x.x
with something that matches the tag for the current release.What this does is that whenever the plugin attempts to push/commit, it will instead push/commit to this branch we created, and finally create the tag from this branch also.
I think this is probably the best option
Disable the
preTagCommit
taskSince the
preTagCommit
task is where it fails, we can disable the task, and it won't be run anymore:Determine for yourself if this is acceptable.
Dynamic push behaviour
Because I've seen the source code, I can see that the reason it pushes is it sees that
git.pushToRemote
is not null. Knowing this, we can dynamically control this behaviour.This way, in the
preTagCommit
, it won't push anything, but will succeed for everything else.