我有一个Jenkins管道,它为我的“引擎”存储库构建和测试Bitbucket上的pull请求 . 我正在使用Bitbucket Pull Request Builder插件,它检查PR分支,对目标分支进行本地合并(使用“Merge Before Build”管道附加行为),然后在我的Jenkinsfile中执行管道 .

测试具有一些存储在其他存储库中的依赖项 . 我的Jenkinsfile将这些检查到子目录中(我也尝试将它们检出到父目录中的新目录中,而不是作为子目录) .

node {
  dir('tools') { git url: 'ssh://git@bitbucket.org:<my_org>/tools.git', branch: 'master', credentialsId: 'my-cred-id' }
}

当这个工具结帐步骤发生时,git插件尝试检查“tools”目录中“engine”repo的HEAD提交:

首先是主要的“引擎”repo克隆(在管道开始之前由Bitbucket插件触发):

> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url git@bitbucket.org:<my_org>/engine.git # timeout=10
Fetching upstream changes from git@bitbucket.org:<my_org>/engine.git
> git --version # timeout=10
using GIT_SSH to set credentials <creds>
> git fetch --tags --progress git@bitbucket.org:<my_org>/engine.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse 2ed413bbaf55^{commit} # timeout=10
> git branch -a -v --no-abbrev --contains 2ed413bbaf551428e5b6328829606155fdb8cd5e # timeout=10
Merging Revision 2ed413bbaf551428e5b6328829606155fdb8cd5e (origin/<branch>) to origin/dev, UserMergeOptions{mergeRemote='origin', mergeTarget='${targetBranch}', mergeStrategy='default', fastForwardMode='--ff'}
> git rev-parse origin/dev^{commit} # timeout=10
> git config core.sparsecheckout # timeout=10
> git checkout -f origin/dev
> git merge --ff 2ed413bbaf551428e5b6328829606155fdb8cd5e # timeout=10
> git rev-parse HEAD^{commit} # timeout=10

然后工具repo clones(由管道中的git命令触发):

> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url git@bitbucket.org:<my_org>/tools.git # timeout=10
Fetching upstream changes from git@bitbucket.org:<my_org>/tools.git
> git --version # timeout=10
using GIT_SSH to set credentials 
> git fetch --tags --progress git@bitbucket.org:<my_org>/tools.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse 2ed413bbaf55^{commit} # timeout=10
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
hudson.plugins.git.GitException: Command "git rev-parse 2ed413bbaf55^{commit}" returned status code 128:
stdout: 2ed413bbaf55^{commit}

stderr: fatal: ambiguous argument '2ed413bbaf55^{commit}': unknown revision or path not in the working tree.

PR分支( 2ed413 )指向的提交SHA与git在签出工具仓库时尝试检出的提交SHA相同,后者在该存储库中不存在 . 我错误配置了我的管道吗?或者这是一个错误?