从Git退房时出现Hudson错误:“必须调用setGitDir或setWorkTree之一”

时间:2013-10-02 17:55:15

标签: git hudson

当我尝试在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配置项目的屏幕截图:

enter image description here enter image description here

3 个答案:

答案 0 :(得分:5)

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

答案 1 :(得分:3)

分享问题并解决我面临的问题的想法。对我来说,这是在Jenkins Sonar工作中从上游Jenkins工作克隆工作区时发生的,该工作执行了代码检查。

问题:在构建后的操作中使用Sonar-runner或使用mvn clean install声纳: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

解决方案:根据&#34; Malte Skoruppa&#34;的link,如果代码未从Git存储库中检出但是以压缩方式下载,则会出现问题包含代码的文件。 因此,通过从Git克隆存储库来解决错误(之前我通过从上游Jenkins作业克隆工作空间来实现此目的)。

答案 2 :(得分:0)

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