詹金斯(Jenkins)没有看到Git的分支机构
我正在运行Jenkins管道,该管道正在获取git回购,例如:
stage('Stash sources') {
steps {
script {
stash name: 'repo_source'
}
}
}
output:
我想比较要这样的分支:
git diff --name-only -r ${env.CHANGE_BRANCH} ${env.CHANGE_TARGET} | xargs -L1 dirname | uniq | awk '{print "./"\$0}'
但是,詹金斯现在没有分支,获取此输出:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您显示的审查图像(顺便说一句,不要使用剪切和粘贴文本将使用的图像),“克隆”存储库来审查的图像:
git Init< path>
)git config remote.origin.url< url< url>
,git config remote.origin.origin.origin.origin.fetch&refspec> refspec> ;
)git提取... - < url> < refspec>
此过程有点愚蠢,因为它可以使用
git clone
和/或而无需重复URL和/或REFSPEC。refspec
您的jenkins代码使用的是:此refspec表示您的git仅副本仅可从
onect> onect> onect> onect
git Repository的prci consection coptions 。
分支;这些提交是在您的存储库中,在 no 分支上,但通过名称Origin/pr-262
找到。然后,您的Jenkins代码运行
Git Checkout 1B6C2CF8AF034BB41661DCE739D9A0058< sosings-obscured>
。大概这是一个完整的原始哈希ID。这不会创建新的分支机构,因此您的存储库仍然没有分支机构。头部
现在在指定的提交中分离。詹金斯本身非常可怕,我不是詹金斯的专家,但这显然不是您想要做的。您需要重新配置它,或使用其他插件或其他内容,或编写Jenkinsfile,以便您更直接地控制所有内容。让Jenkins运行
git克隆
和/或使用适当的RefSpec复制或创建您想要的所有分支。一种简单的方法(尽管略昂贵)的方法是制作完整的克隆并复制 ash 分支:或者您可以在
refs/promotes/promne/oneques/onect/名称> git diff 。也就是说,
您可以使用:(
但是您仍然需要一个完整的克隆,而不是将分支
prci
更改为远程跟踪pr-262
的一个完整的克隆。 )。这里可能还有其他事情要解释奇怪的refspec传递给
git提取
的原因,值得一提。Your Jenkins setup, according to the censored image you showed (by the way, don't use images where cut and paste text will serve), "clones" the repository by:
git init <path>
)git config remote.origin.url <url>
,git config remote.origin.fetch <refspec>
)git fetch ... -- <url> <refspec>
This process is a little bit silly as it could be done with
git clone
and/or without repeating the URL and/or refspec.The
refspec
that your Jenkins code uses is:This refspec means that your Git copies only the commits reachable from the
origin
Git repository'sPRCI
branch; those commits are, in your repository, on no branch, but are found by the nameorigin/PR-262
.Your Jenkins code then runs
git checkout 1b6c2cf8af034bb41661dce739d9a0058<something-obscured>
. Presumably this is a full raw hash ID. This creates no new branches, so your repository continues to have no branches at all;HEAD
is now detached at the specified commit.Jenkins itself is pretty horrible and I'm no Jenkins expert, but this is clearly not what you want it to do. You'll need to reconfigure it, or use a different plug-in, or something, or write a Jenkinsfile so that you control everything much more directly. Have your Jenkins run
git clone
properly and/or have it copy or create all the branches you want using a proper refspec. A simple (though slightly expensive) way would be to make a full clone and copy all branches:or you could use the
refs/remotes/origin/
names in yourgit diff
. That is, instead of:you could use:
(but you'd still need a full clone, not one that changes branch
PRCI
into remote-tracking-namePR-262
).There is probably something else going on here that explains the reason for the weird refspec passed to
git fetch
, and it would be worth figuring out what that is.您是否将两个分支都签到了您的本地工作空间?如果您的
change_target
分支在遥控器中且未在本地检查,则Git找不到分支进行差异。错误指出该分支在您的工作树中不可用,这是指您的本地文件系统。因此,首先结帐,然后您在执行差异时毫不费力。Do you have both branches checked out into your local workspace? If your
CHANGE_TARGET
branch is in a remote and not checked out locally, then git cannot find the branch to do the diff. The error states that the branch is not available in your working tree, and this refers to your local file system. So do the checkout first, and then you should have no trouble performing the diff.