简体   繁体   English

我怎么能在詹金斯git fetch --unshallow?

[英]How can I git fetch --unshallow in Jenkins?

I am integrating SonarQube into Jenkins. 我正在将SonarQube整合到Jenkins中。 We currently use shallow clones because our repository is slow to clone entirely given a large binary files in history. 我们目前使用浅克隆,因为我们的存储库在历史记录中给定大型二进制文件时完全克隆很慢。 SonarQube needs to run git blame which apparently doesn't work on shallow clones. SonarQube需要运行git blame ,这显然不适用于浅层克隆。 I need a workaround, but I can't change the global Jenkins config (it would slow down all builds). 我需要一个解决方法,但我无法更改全局Jenkins配置(它会减慢所有构建)。

Situation: 情况:

checkout scm works with no arguments. checkout scm不带参数。

sh 'git fetch --unshallow gets an error as it doesn't have credentials. sh 'git fetch --unshallow因为没有凭据而收到错误。

I've tried this monstrosity to customize the arguments to checkout scm: 我已经尝试过这个怪物来自定义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

But I get this error: 但我得到这个错误:

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

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

Reported issues seem to center around failing to provide "Name of repository": 报告的问题似乎以未能提供“存储库名称”为中心:

I was trying to build a Pull Request and it did not have the refspec for the change. 我正在尝试构建一个Pull Request,它没有针对更改的refspec。 I don't know why it couldn't infer that, but it doesn't. 我不知道为什么它不能推断出来,但事实并非如此。

Here's what worked to address that first part: 以下是解决第一部分的问题:

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]
               ]
]

The checkout works, the build works, but I still get a shallow 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

Here's what I have under Project - GitHub Organization in Jenkins configuration: 这是我在Project - Jenkins配置中的GitHub组织下所拥有的: 高级克隆行为

Here's what I want for a specific build step: checkout scm , but with the shallow "unchecked" in code. 这是我想要的特定构建步骤: checkout scm ,但在代码中使用浅“unchecked”。

How can I git fetch --unshallow in Jenkins? 我怎么能在詹金斯git fetch --unshallow?

This is not possible with the git jenkins plugin as of version git-4.0.0-beta3. 对于git-4.0.0-beta3版本的git jenkins插件,这是不可能的。 There is no support or mention whatsoever in the source for the unshallow parameter of git fetch . git fetchunshallow参数在源代码中没有任何支持或提及

What you can do is leave out your git jenkins plugin option as is: shallow first fetch so it's faster. 你可以做的就是省略你的git jenkins插件选项:浅的第一次获取所以它更快。

Then you have some options: 然后你有一些选择:

  • In the execute shell for the build you can run the unshallow procedure by using git directly, not via the plugin. 在构建的执行shell中,您可以直接使用git运行unshallow过程,而不是通过插件。
  • If this would slow down too many builds, have a prerun step before SonarQube go into the workspace and run the unshallow procedure. 如果这会减慢太多构建,请在SonarQube进入工作区并运行unshallow过程之前执行预运行步骤。 This can be done via a Groovy script among other things. 这可以通过Groovy脚本等来完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM