简体   繁体   English

Gradle-release-plugin 更新被拒绝,因为您当前分支的尖端落后

[英]Gradle-release-plugin Updates were rejected because the tip of your current branch is behind

At my workplace, we use a monthly release branch that's shared across several developers.在我的工作场所,我们使用由多个开发人员共享的月度发布分支。

Gradle version is 2.14.1 Gradle版本是2.14.1

We manually trigger the code build and release (task) using Jenkins (which is effective running - gradle clean compileJava release)我们使用 Jenkins 手动触发代码构建和发布(任务)(有效运行 - 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.整个过程大约需要 30-40 分钟,基本上是编译、生成工件、运行 Junit 测试并将工件上传到 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.最终到了标记和推送版本号的步骤: preTagCommit ,它尝试更新 gradle.properties 并将版本号提高到它并提交和推送。

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.此时,如果最近 30-40 分钟(由于手动触发构建)分支上没有提交,则发布成功。

The moment there is even a single commit between the whole process it fails with error: Execution failed for task ':preTagCommit'.在整个过程之间甚至有一个提交的那一刻它失败并出现错误:任务':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.抱歉,如果之前有人问过这个问题,我发现的所有解决方案都是 git 的一般方法,而不是来自使用带有 git 的 Gradle-Release-Plugin 的人。

Any response will be greatly appreciated.任何回应将不胜感激。

I believe the flag you're looking for is mentioned in the GitHub page of the plugin:我相信插件的GitHub 页面中提到了您要查找的标志:

Eg.例如。 To ignore upstream changes, change 'failOnUpdateNeeded' to false:要忽略上游更改,请将“failOnUpdateNeeded”更改为 false:

release {
  failOnUpdateNeeded = false
}

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 the release extension (what a mouthful to say).然而,还有另一种方法可以做到这一点,那就是在release扩展的git选项中添加一个强制推送选项(多嘴多说)。

release {
  git {
    pushOptions = ['--force']
  }
}

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).正如我在下面的最后一条评论中所说,失败的部分是扩展运行preTagCommit任务,然后尝试将此提交推送到上游分支(例如master )。 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不要将 preTag 提交推送到上游

or或者

Push preTagCommits to a branch named foo将 preTagCommits 推送到名为 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.所以我想出了一些hacky解决方案来规避这个问题。

Solutions/Hacks解决方案/黑客

Specify pushToBranchPrefix Create a tagged branch指定 pushToBranchPrefix创建标记分支

This is another option that can be passed to the git object which causes all pushes it does to be done to a specific branch with a given prefix rather than the current branch:这是另一个可以传递给git object 的选项,这会导致它所做的所有推送都执行到具有给定前缀的特定分支而不是当前分支:

For example:例如:

afterReleaseBuild {
  doFirst {
    project.exec {
        executable = 'git'
        args 'checkout', '-b', 'v1.x.x@master'
    }
  }
}

Replace v1.xx with something that matches the tag for the current release.v1.xx替换为与当前版本的标签匹配的内容。

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 task禁用preTagCommit任务

Since the preTagCommit task is where it fails, we can disable the task, and it won't be run anymore:由于preTagCommit任务失败了,我们可以禁用该任务,它将不再运行:

tasks.named('preTagCommit') {
    enabled = false
}

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.因为看过源码,可以看出它推送的原因是它看到git.pushToRemote不是null。 Knowing this, we can dynamically control this behaviour.知道了这一点,我们就可以动态地控制这种行为。

tasks.named('preTagCommit') {
  def pushToRemote = null
  doFirst {
    project.extensions.configure(net.researchgate.release.ReleaseExtension) {
      pushToRemote = it.git.pushToRemote
      it.git.pushToRemote = null
    }
  }

  doLast {
    project.extensions.configure(net.researchgate.release.ReleaseExtension) {
      it.git.pushToRemote = pushToRemote
    }
  }
}

This way, in the preTagCommit , it won't push anything, but will succeed for everything else.这样,在preTagCommit中,它不会推送任何内容,但会成功处理其他所有内容。

The easiest way out for my situation was to simply modify for my release plugin component in the build.gradle:针对我的情况,最简单的方法是简单地修改 build.gradle 中的发布插件组件:

***
release {
....
 pushToRemote = ''
....
}
***

This ensures the release plugin doesn't push!这确保了发布插件不会推送!

After control comes from the gradle release, I followed up with:在控制来自 gradle 版本后,我跟进:

Git pull origin Git 拉原点

Git push --tags origin Git 推送--标签来源

This nicely synchronized my commits and also follows the pull before push rule!这很好地同步了我的提交,并且还遵循了先拉后推规则!

Though this is a hacky solution, I was suggested by @Clijsters to use Special release branches to solve this issue.虽然这是一个 hacky 解决方案,但 @Clijsters 建议我使用特殊版本分支来解决这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更新被拒绝,因为您当前分支的提示落后 - 但为什么? - Updates were rejected because the tip of your current branch is behind - but why? 更新被拒绝,因为您当前分支的尖端在后面...不正确 - Updates were rejected, because the tip of your current branch is behind… Not true Git 更新被拒绝,因为您当前分支(主)的尖端在后面但是分支是最新的? - Git Updates were rejected because the tip of your current branch (main) is behind BUT branch is up to date? GitLab 更新被拒绝,因为您当前分支的尖端落后于其远程对应分支 - GitLab Updates were rejected because the tip of your current branch is behind its remote counterpart 源树推送:提示:更新被拒绝,因为当前分支的尖端落后 - Source Tree Push : hint: Updates were rejected because the tip of your current branch is behind Github 错误“更新被拒绝,因为您当前分支的提示落后” - Github error "Updates were rejected because the tip of your current branch is behind" git:“更新被拒绝,因为您当前分支的尖端落后..”但是如何查看差异? - git: "Updates were rejected because the tip of your current branch is behind.." but how to see differences? 如何解决 git 错误:“更新被拒绝,因为您当前分支的提示落后了” - How to resolve git error: "Updates were rejected because the tip of your current branch is behind" 更新被拒绝,因为你当前分支的尖端落后于它的远程分支 - Updates were rejected because the tip of your current branch is behind its remote counterpart 收到错误“更新被拒绝,因为您当前分支的提示落后了” - Getting error “Updates were rejected because the tip of your current branch is behind”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM