Git 使用多个存储库推送 Jenkins 会产生存储库未找到错误

Git push in Jenkins with multiple repos yields repository not found errors

我在 "Source Code Management" 部分配置了一个包含多个存储库的 Jenkins 作业,每个存储库都有一个 "custom" 原始名称。用例是我需要从第一个 repo 中提取校验和值,然后使用它来更新第二个 repo 中的文件并将该更改推送到远程 repo。 Jenkins 作业输出如下所示:

> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from 2 remote Git repositories
 > git config remote.second-origin.url git@github.com:user/repo-2.git # timeout=10
Fetching upstream changes from git@github.com:user/repo-2.git
 > git --version # timeout=10
using GIT_SSH to set credentials 
 > git fetch --tags --progress git@github.com:user/repo-2.git +refs/heads/*:refs/remotes/second-origin/*
 > git config remote.first-origin.url git@github.com:user/repo-1.git # timeout=10
Fetching upstream changes from git@github.com:user/repo-1.git
using GIT_SSH to set credentials 
 > git fetch --tags --progress git@github.com:user/repo-1.git +refs/heads/*:refs/remotes/first-origin/*
Seen branch in repository second-origin/development
Seen branch in repository second-origin/master
Seen branch in repository first-origin/master
Seen branch in repository first-origin/test
Seen 4 remote branches
Checking out Revision 15j5123hjhjkl5123jk512hjkl5hjk5jhkl (first-origin/test)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 15j5123hjhjkl5123jk512hjkl5hjk5jhkl
 > git rev-list 15j5123hjhjkl5123jk512hjkl5hjk5jhkl # timeout=10
[Jenkins Job] $ /bin/sh -xe /tmp/hudson2801366816478454446.sh
+ git config --global user.name jenkins-deploy
+ git config --global user.email jenkins-deploy@test.com
+ git checkout first-origin/master
Previous HEAD position was 15j51... Some stuff
HEAD is now at f2f34af23.. Merging master
++ git rev-parse HEAD
+ echo f2f34af23a2g3hLKJHGQLK2HJ > current.rev
+ git branch -d development
warning: deleting branch 'development' that has been merged to
         'refs/remotes/second-origin/development', but it is not yet merged to HEAD.
Deleted branch development (was 15bfafb).
+ git checkout -b development second-origin/development
Previous HEAD position was f8c45cf... Merging master
Switched to a new branch 'development'
Branch development set up to track remote branch development from second-origin.
+ cat current.rev >> file-changed.txt
+ git add file-changed.txt
+ git commit -m 'updating file-changed.txt'
[development 4fd83aa] updating file-changed.txt
 1 files changed, 1 insertions(+), 1 deletions(-)
+ git push second-origin development
ERROR: Repository not found.
fatal: The remote end hung up unexpectedly
Build step 'Execute shell' marked build as failure
Notifying upstream projects of job completion
Finished: FAILURE

我也尝试了所有我能想到的 git push 命令,但没有任何效果:

git push -u second-origin development
git push
git push development
git push second-origin/development
git push second-origin:development
git push second-origin
git push remotes/second-origin
git push remotes/second-origin/development
git push second-origin user/repo-2/development
git push second-origin user/repo-2:development
git push second-origin user/repo-2 development

我感觉这与 Jenkins 插入 git config core.sparsecheckout 有关,但找不到关于该主题的任何有用信息。

我通过更新 shell 命令解决了这个问题:

  1. 让它成为常规 git checkout second-origin/development
  2. 删除了 git 推送,然后我添加了 post-构建步骤 使用 Git Pulisher 推送我想要的分支 second-origin.