3

当我尝试在 Hudson 上从 GIT 构建项目时出现错误。该项目位于 GitHub 中,如果这可能会有所不同的话。

错误是:

FATAL: One of setGitDir or setWorkTree must be called.

我无法在网上或 StackOverflow 上找到有关如何处理此问题的任何有用信息。我什至不知道从哪里开始解决这个问题。

这是完整的控制台输出:

Started by user anonymous
Checkout:workspace / D:\Hudson\jobs\{Name of App}\workspace - hudson.remoting.LocalChannel@1c2a5b50
Using strategy: Default
Checkout:workspace / D:\Hudson\jobs\{Name of App}\workspace - hudson.remoting.LocalChannel@1c2a5b50
FATAL: One of setGitDir or setWorkTree must be called.
java.lang.IllegalArgumentException: One of setGitDir or setWorkTree must be called.
    at org.eclipse.jgit.lib.BaseRepositoryBuilder.requireGitDirOrWorkTree(BaseRepositoryBuilder.java:538)
    at org.eclipse.jgit.lib.BaseRepositoryBuilder.setup(BaseRepositoryBuilder.java:506)
    at org.eclipse.jgit.storage.file.FileRepositoryBuilder.build(FileRepositoryBuilder.java:89)
    at hudson.plugins.git.GitAPI.<init>(GitAPI.java:92)
    at hudson.plugins.git.GitSCM$3.invoke(GitSCM.java:897)
    at hudson.plugins.git.GitSCM$3.invoke(GitSCM.java:889)
    at hudson.FilePath.act(FilePath.java:791)
    at hudson.FilePath.act(FilePath.java:773)
    at hudson.plugins.git.GitSCM.gerRevisionToBuild(GitSCM.java:889)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:668)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1515)
    at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:521)
    at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:428)
    at hudson.model.Run.run(Run.java:1390)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:40)
    at hudson.model.ResourceController.execute(ResourceController.java:82)
    at hudson.model.Executor.run(Executor.java:137)

以下是显示我如何使用 GIT 配置项目的屏幕截图:

在此处输入图像描述 在此处输入图像描述

4

3 回答 3

5

嗯。不知道为什么这解决了它,但我能够通过清除工作区来消除错误。

于 2013-10-04T19:40:56.257 回答
3

想到分享我面临的问题的问题和解决方案。对我来说,这是在从进行代码签出的上游 Jenkins 作业中克隆 Jenkins Sonar 作业中的工作区时发生的。

问题:尝试在构建后操作中使用 Sonar-runner 或使用 mvn clean install sonar:sonar 分析带有 Sonar 的项目时,我遇到了以下问题:

[ERROR] One of setGitDir or setWorkTree must be called.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.072 s
[INFO] Finished at: 2015-03-09T05:11:28-04:00
[INFO] Final Memory: 21M/453M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.4:sonar (default-cli) on project OnlineBanking: One of setGitDir or setWorkTree must be called. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.4:sonar (default-cli) on project OnlineBanking: One of setGitDir or setWorkTree must be called.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:160)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: One of setGitDir or setWorkTree must be called.
    at org.codehaus.mojo.sonar.bootstrap.ExceptionHandling.handle(ExceptionHandling.java:42)
    at org.codehaus.mojo.sonar.bootstrap.RunnerBootstraper.execute(RunnerBootstraper.java:135)
    at org.codehaus.mojo.sonar.SonarMojo.execute(SonarMojo.java:136)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 19 more
Caused by: java.lang.IllegalArgumentException: One of setGitDir or setWorkTree must be called.
    at org.eclipse.jgit.lib.BaseRepositoryBuilder.requireGitDirOrWorkTree(BaseRepositoryBuilder.java:582)
    at org.eclipse.jgit.lib.BaseRepositoryBuilder.setup(BaseRepositoryBuilder.java:550)
    at org.eclipse.jgit.lib.BaseRepositoryBuilder.build(BaseRepositoryBuilder.java:573)
    at org.sonar.plugins.scm.git.JGitBlameCommand.buildRepository(JGitBlameCommand.java:92)
    at org.sonar.plugins.scm.git.JGitBlameCommand.blame(JGitBlameCommand.java:57)
    at org.sonar.batch.scm.ScmSensor.execute(ScmSensor.java:88)
    at org.sonar.batch.scan.SensorWrapper.analyse(SensorWrapper.java:74)
    at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:79)
    at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:70)
    at org.sonar.batch.phases.PhaseExecutor.execute(PhaseExecutor.java:122)
    at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:222)
    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:93)
    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:78)
    at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:235)
    at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:230)
    at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:223)
    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:93)
    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:78)
    at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:65)
    at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:52)
    at org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.java:128)
    at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:93)
    at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:78)
    at org.sonar.batch.bootstrap.BootstrapContainer.executeTask(BootstrapContainer.java:171)
    at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:95)
    at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
    at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87)
    at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
    at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
    at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
    at org.sonar.runner.api.Runner.execute(Runner.java:100)
    at org.codehaus.mojo.sonar.bootstrap.RunnerBootstraper.execute(RunnerBootstraper.java:131)
    ... 22 more
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Sonar analysis completed: FAILURE
Build step 'Sonar' changed build result to FAILURE
Build step 'Sonar' marked build as failure
[BFA] Scanning build for known causes...

[BFA] Done. 0s
Finished: FAILURE

解决方案:根据“Malte Skoruppa”的链接,当代码未从 Git 存储库中签出而是作为包含代码的压缩文件下载时,就会出现此问题。因此,通过从 Git 克隆存储库解决了错误(以前我是通过从上游 Jenkins 作业克隆工作区来实现的)。

于 2015-03-09T10:28:15.027 回答
0

对于在 Android 项目上遇到此问题的人:这发生在我身上,因为我试图通过 zip 导入 Android 项目,问题是在项目中找不到 Git 元数据。我的解决方案是从 git 克隆项目。

于 2019-08-02T18:28:06.920 回答