gpt4 book ai didi

git - 我怎样才能 git fetch --unshallow 在 Jenkins ?

转载 作者:太空狗 更新时间:2023-10-29 14:10:16 25 4
gpt4 key购买 nike

我正在将 SonarQube 集成到 Jenkins 中。我们目前使用浅层克隆,因为我们的存储库在历史上有一个大的二进制文件时完全克隆很慢。 SonarQube 需要运行 git blame,这显然不适用于浅层克隆。我需要一个解决方法,但我无法更改全局 Jenkins 配置(它会减慢所有构建速度)。

情况:

checkout scm 不带任何参数。

sh 'git fetch --unshallow 收到错误,因为它没有凭据。

我已经尝试过这种怪异的方式来自定义 checkout scm 的参数:

checkout scm: [
$class: 'GitSCM', userRemoteConfigs: [
[url: env.repoURL, credentialsId: 'GitHubEnterprise']
], extensions: [
[$class: 'CheckoutOption', timeout: 60],
[$class: 'CloneOption', noTags: true,
reference: '/var/lib/gitchcache/reference.git',
shallow: false, timeout: 60]
], branches: [
[name: branch]
]
], remoteName: "origin", poll: false, clearWorkspace: true

但是我得到这个错误:

> git rev-parse PR-42^{commit} # timeout=10

Couldn't find any revision to build. Verify the repository
and branch configuration for this job.

报告的问题似乎集中在未能提供“存储库名称”方面:

我正在尝试构建一个 Pull Request,但它没有更改的 refspec。我不知道为什么它不能推断出这一点,但事实并非如此。

以下是解决第一部分的方法:

checkout scm: [$class: 'GitSCM',
userRemoteConfigs: [
[url: env.GIT_URL,
refspec: "+refs/pull/${prNumber}/head:refs/remotes/origin/${branch}",
credentialsId: 'GitHubEnterprise']
],
extensions: [
[$class: 'CloneOption',
shallow: false,
timeout: 60]
],
branches: [
[name: branch]
]
]

checkout 有效,构建有效,但我仍然得到浅 checkout ...

INFO: SCM provider for this project is: git
INFO: 1 files to be analyzed
WARN: Shallow clone detected, no blame information will be provided. You can convert to non-shallow with 'git fetch --unshallow'.
INFO: 0/1 files analyzed
WARN: Missing blame information for the following files:
WARN: * src/main/java/com/example/Example.java

这是我在 Jenkins 配置中的 Project - GitHub Organization 下的内容: Advanced clone behaviours

这是我想要的特定构建步骤:checkout scm,但代码中的浅层“未检查”。

如何在 Jenkins 中使用 git fetch --unshallow?

最佳答案

从版本 git-4.0.0-beta3 开始,这对于 git jenkins 插件是不可能的。 There is no support or mention whatsoevergit fetchunshallow 参数的源代码中。

你可以做的是保留你的 git jenkins 插件选项:shallow first fetch so it is faster.

然后你有一些选择:

  • 在构建的执行 shell 中,您可以直接使用 git 运行 unshallow 程序,而不是通过插件。
  • 如果这会降低太多构建的速度,请在 SonarQube 进入工作区并运行 unshallow 过程之前执行预运行步骤。这可以通过 Groovy 脚本等方式完成。

关于git - 我怎样才能 git fetch --unshallow 在 Jenkins ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52559384/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com