James Dunn
James Dunn

Reputation: 8274

Hudson error when checking out from Git: "One of setGitDir or setWorkTree must be called"

I'm getting an error when I attempt to build a project from GIT on Hudson. The project is in GitHub, if that might make a difference.

The error is:

FATAL: One of setGitDir or setWorkTree must be called.

I haven't been able to find any useful information online or on StackOverflow for how to deal with this. I don't even know where to begin to figure this out.

This is the full console output:

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)

Here are screen shots showing how I have the project configured with GIT:

enter image description here enter image description here

Upvotes: 3

Views: 8861

Answers (3)

kassour taoufik
kassour taoufik

Reputation: 1

For people who have this problem on Android project: It happened to me because I was trying to import Android Project through zip and the issue was that no Git metadata was found on the project. My Solution was to clone the project from git.

Upvotes: 0

thefiestypanther
thefiestypanther

Reputation: 79

Thought of sharing the issue and resolution to the issue I was facing. For me it was happening while cloning the workspace in Jenkins Sonar job from an upstream Jenkins job that did code checkout.

Issue: While trying to analyze a project with Sonar using Sonar-runner in the post-build action or with mvn clean install sonar:sonar, I faced the following issue:

[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

Resolution: As per the link by "Malte Skoruppa", the issue happens when code is not checked-out from Git repository but is downloaded as a zipped file containing the code. So, error got resolved by cloning the Repository from Git (previously I was achieving this by cloning the workspace from an upstream Jenkins job).

Upvotes: 3

James Dunn
James Dunn

Reputation: 8274

Huh. Not sure why this solved it, but I was able to make the error go away by Wiping Out the Workspace.

Upvotes: 5

Related Questions