我在 Jenkins 1.500 上使用当前版本的 Git 插件(SCM 提供者和发布者)。SCM 轮询工作正常,使用我的 git HTTP URL 和“功能-*”的“构建分支”设置。这会获取对任何分支的更改,例如“feature-1234”,运行构建/测试/覆盖任务,并报告成功或失败。所有这些工作都很好,包括来自集成分支的合并,代码应该在成功构建和代码审查后结束。
问题在于尝试将完成的构建分支推回原点,在同一个“feature-1234”分支上。在这种情况下,构建变量“GIT_BRANCH”包含“origin/feature-1234”,它会在构建成功后在 Git Publisher 中产生以下错误和失败:
Pushing HEAD to branch origin/feature-1234 at repo origin
ERROR: Failed to push branch origin/feature-1234 to origin
hudson.plugins.git.GitException: Command "/usr/bin/git push https://jenkins:jenkinsPWD@myproject.com/git/project HEAD:origin/feature-1234" returned status code 1:
stdout:
stderr: error: unable to push to unqualified destination: origin/feature-1234
The destination refspec neither matches an existing ref on the remote nor
begins with refs/, and we are unable to guess a prefix based on the source ref.
error: failed to push some refs to 'https://jenkins:jenkinsPWD@myproject.com/git/project'
at hudson.plugins.git.GitAPI.launchCommandIn(GitAPI.java:897)
at hudson.plugins.git.GitAPI.launchCommand(GitAPI.java:858)
at hudson.plugins.git.GitAPI.push(GitAPI.java:915)
at hudson.plugins.git.GitPublisher$4.invoke(GitPublisher.java:351)
at hudson.plugins.git.GitPublisher$4.invoke(GitPublisher.java:333)
at hudson.FilePath.act(FilePath.java:865)
at hudson.FilePath.act(FilePath.java:838)
at hudson.plugins.git.GitPublisher.perform(GitPublisher.java:333)
at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:36)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:810)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:785)
at hudson.model.Build$BuildExecution.post2(Build.java:183)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:732)
at hudson.model.Run.execute(Run.java:1582)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:236)
Build step 'Git Publisher' changed build result to FAILURE
Build step 'Git Publisher' marked build as failure
看到那里额外的“起源”了吗?origin/feature-1234 <== 这是 ${GIT_BRANCH} 的当前值,虽然我知道它是一个远程分支,但它阻止了我运行我们想要遵循的过程。
如果我错过了一些简单的东西,我很想听听。但是我已经为构建中与 git 相关的各个部分尝试了许多不同的设置,但似乎没有什么可以让我将合并和测试的代码提交回工作分支(与集成分支相反,这很容易做到。