Skip to content

Commit

Permalink
How a GitToolChooser would work within the Git Plugin
Browse files Browse the repository at this point in the history
The process of recommending an optimal git impl is in two stages:
Stage 1: Determine if the user additional behavior contains a feature which is not supported
by JGit - see UnsupportedCommand usage
Stage 2: Instantiating GitToolChooser to recommend a git tool
Here, the GitToolChooser uses the repository URL to determine a recommendation for the git
implementation.
  • Loading branch information
rishabhBudhouliya committed Aug 17, 2020
1 parent 3484e78 commit 3b26071
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/main/java/hudson/plugins/git/GitSCM.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import hudson.util.ListBoxModel;
import jenkins.model.Jenkins;
import jenkins.plugins.git.GitSCMMatrixUtil;
import jenkins.plugins.git.GitToolChooser;
import net.sf.json.JSONObject;

import org.eclipse.jgit.errors.MissingObjectException;
Expand All @@ -68,13 +69,7 @@
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.URIish;
import org.jenkinsci.plugins.gitclient.ChangelogCommand;
import org.jenkinsci.plugins.gitclient.CheckoutCommand;
import org.jenkinsci.plugins.gitclient.CliGitAPIImpl;
import org.jenkinsci.plugins.gitclient.CloneCommand;
import org.jenkinsci.plugins.gitclient.FetchCommand;
import org.jenkinsci.plugins.gitclient.Git;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.jenkinsci.plugins.gitclient.*;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
Expand Down Expand Up @@ -844,7 +839,25 @@ public GitClient createClient(TaskListener listener, EnvVars environment, Run<?,
/*package*/ GitClient createClient(TaskListener listener, EnvVars environment, Job project, Node n, FilePath ws) throws IOException, InterruptedException {

String gitExe = getGitExe(n, listener);
Git git = Git.with(listener, environment).in(ws).using(gitExe);

This comment has been minimized.

Copy link
@marekdovjak

marekdovjak Sep 2, 2020

@rishabhBudhouliya I think that after this change jenkins ignores that I have overriden git tool location on jenkins slave.

My jenkins master runs on Windows machine, in jenkins global tool configuration, path to git executable is set to "git.exe". Then I have jenkins node running on MacOS. In the MacOS node properties, the git tool location is overriden. But my multibranch pipeline job ignores this overriden value and wants to run git.exe on MacOS.

I've downgraded the git plugin to 4.3.0 to make it work again.
this is the error:

Running on mac builder in /Users/MAC/Jenkins/workspace/_TAP-3454-ios---pomiesane-jazyky
[Pipeline] {
[Pipeline] checkout
The recommended git tool is: git.exe
using credential ba4f5f50-345a-4c20-8216-b10bb2968120
Cloning the remote Git repository
Cloning with configured refspecs honoured and without tags
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Could not init /Users/MAC/Jenkins/workspace/_TAP-3454-ios---pomiesane-jazyky
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:997)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:752)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:161)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:154)
at hudson.remoting.UserRequest.perform(UserRequest.java:211)
at hudson.remoting.UserRequest.perform(UserRequest.java:54)
at hudson.remoting.Request$2.run(Request.java:375)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:73)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:118)
at java.lang.Thread.run(Thread.java:748)
Suppressed: hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from MACBOOK-PRO/192.168.100.148:49597
at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1800)
at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:357)
at hudson.remoting.Channel.call(Channel.java:1001)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.execute(RemoteGitImpl.java:146)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.invoke(RemoteGitImpl.java:132)
at com.sun.proxy.$Proxy85.execute(Unknown Source)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1173)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1251)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:125)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:93)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:80)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: hudson.plugins.git.GitException: Error performing git command: git.exe init /Users/MAC/Jenkins/workspace/_TAP-3454-ios---pomiesane-jazyky
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2457)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2380)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2376)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1923)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:995)
... 12 more
Caused by: java.io.IOException: Cannot run program "git.exe" (in directory "/Users/MAC/Jenkins/workspace/_TAP-3454-ios---pomiesane-jazyky"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at hudson.Proc$LocalProc.(Proc.java:252)
at hudson.Proc$LocalProc.(Proc.java:221)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:996)
at hudson.Launcher$ProcStarter.start(Launcher.java:508)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2443)
... 16 more
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.(UNIXProcess.java:247)
at java.lang.ProcessImpl.start(ProcessImpl.java:134)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 21 more

This comment has been minimized.

Copy link
@MarkEWaite

MarkEWaite Sep 2, 2020

Contributor

Thanks @marekdovjak ! Work is progressing to fix JENKINS-63519.


UnsupportedCommand unsupportedCommand = new UnsupportedCommand();
for (GitSCMExtension ext : extensions) {
ext.determineSupportForJGit(this, unsupportedCommand);
}

listener.getLogger().println("Using Performance Improvement");
GitToolChooser chooser = null;
for (UserRemoteConfig uc : getUserRemoteConfigs()) {
String url = getParameterString(uc.getUrl(), environment);
chooser = new GitToolChooser(url, project, null, gitExe, unsupportedCommand.determineSupportForJGit());
}
listener.getLogger().println("The recommended git tool is: " + chooser.getGitTool());
String updatedGitExe = chooser.getGitTool();

if (updatedGitExe.equals("NONE")){
updatedGitExe = gitExe;
}
Git git = Git.with(listener, environment).in(ws).using(updatedGitExe);

GitClient c = git.getClient();
for (GitSCMExtension ext : extensions) {
Expand Down

0 comments on commit 3b26071

Please sign in to comment.