詹金斯(Jenkins)没有看到Git的分支机构

发布于 2025-02-10 14:18:18 字数 498 浏览 1 评论 0 原文

我正在运行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}'

但是,詹金斯现在没有分支,获取此输出:

I am running a jenkins pipeline, which is fetching git repo like this:

stage('Stash sources') {
    steps {
        script {
            stash name: 'repo_source'
        }
    }
}

Output:

enter image description here

Then I want to compare to branches like this:

git diff --name-only -r ${env.CHANGE_BRANCH} ${env.CHANGE_TARGET} | xargs -L1 dirname | uniq | awk '{print "./"\$0}'

But, Jenkins doesn't have the branches now, getting this output:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泪痕残 2025-02-17 14:18:18

根据您显示的审查图像(顺便说一句,不要使用剪切和粘贴文本将使用的图像),“克隆”存储库来审查的图像:

  • 创建一个空存储库(一个没有提交且没有分支:一个没有分支: 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代码使用的是:

+refs/heads/PRCI:refs/remotes/origin/PR-262

此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 分支:

git fetch origin '+refs/heads/*:refs/heads/*'

或者您可以在 refs/promotes/promne/oneques/onect/名称> git diff 。也就是说,

git diff --name-only -r ${env.CHANGE_BRANCH} ${env.CHANGE_TARGET} | ...

您可以使用:(

git diff --name-only -r origin/${env.CHANGE_BRANCH} origin/${env.CHANGE_TARGET} | ...

但是您仍然需要一个完整的克隆,而不是将分支 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:

  • creating an empty repository (one with no commits and no branches: git init <path>)
  • adding a remote (git config remote.origin.url <url>, git config remote.origin.fetch <refspec>)
  • running 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:

+refs/heads/PRCI:refs/remotes/origin/PR-262

This refspec means that your Git copies only the commits reachable from the origin Git repository's PRCI branch; those commits are, in your repository, on no branch, but are found by the name origin/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:

git fetch origin '+refs/heads/*:refs/heads/*'

or you could use the refs/remotes/origin/ names in your git diff. That is, instead of:

git diff --name-only -r ${env.CHANGE_BRANCH} ${env.CHANGE_TARGET} | ...

you could use:

git diff --name-only -r origin/${env.CHANGE_BRANCH} origin/${env.CHANGE_TARGET} | ...

(but you'd still need a full clone, not one that changes branch PRCI into remote-tracking-name PR-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.

赤濁 2025-02-17 14:18:18

您是否将两个分支都签到了您的本地工作空间?如果您的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文