Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-20218] slave can't access Jenkins.instance to retrieve…
… proxy
  • Loading branch information
ndeloof committed Oct 23, 2013
1 parent 2d88a4e commit 0b90466
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Expand Up @@ -94,6 +94,11 @@
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.8</version>
</dependency>
</dependencies>

<scm>
Expand Down
@@ -1,6 +1,7 @@
package org.jenkinsci.plugins.gitclient;

import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import hudson.ProxyConfiguration;
import hudson.plugins.git.GitException;
import hudson.remoting.Channel;
import jenkins.model.Jenkins.MasterComputer;
Expand Down Expand Up @@ -78,4 +79,10 @@ public void setCredentials(StandardUsernameCredentials cred) {
clearCredentials();
addDefaultCredentials(cred);
}

protected ProxyConfiguration proxy;

public void setProxy(ProxyConfiguration proxy) {
this.proxy = proxy;
}
}
Expand Up @@ -9,6 +9,8 @@
import hudson.Launcher.LocalLauncher;
import hudson.model.TaskListener;
import hudson.plugins.git.*;
import hudson.remoting.Callable;
import hudson.slaves.SlaveComputer;
import hudson.util.ArgumentListBuilder;
import hudson.util.IOUtils;
import hudson.util.Secret;
Expand Down Expand Up @@ -37,6 +39,7 @@
import java.net.URISyntaxException;
import java.text.MessageFormat;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -1368,7 +1371,6 @@ private String getURLWithCrendentials(URIish u, StandardCredentials cred) {
client.getState().setCredentials(AuthScope.ANY, defaultcreds);
}

ProxyConfiguration proxy = Jenkins.getInstance().proxy;
if (proxy != null) {
client.getHostConfiguration().setProxy(proxy.name, proxy.port);
client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxy.getUserName(), proxy.getPassword()));
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/jenkinsci/plugins/gitclient/Git.java
Expand Up @@ -6,6 +6,7 @@
import hudson.model.TaskListener;
import hudson.plugins.git.GitAPI;
import hudson.remoting.VirtualChannel;
import jenkins.model.Jenkins;

import javax.annotation.Nullable;
import java.io.File;
Expand Down Expand Up @@ -62,7 +63,10 @@ public GitClient invoke(File f, VirtualChannel channel) throws IOException, Inte
return new GitAPI(exe, f, listener, env);
}
};
return repository!=null ? repository.act(callable) : callable.invoke(null,null);
GitClient git = (repository!=null ? repository.act(callable) : callable.invoke(null,null));
if (Jenkins.getInstance() != null)
git.setProxy(Jenkins.getInstance().proxy);
return git;
}

// Can be use to force use of the 100% backward-compatible CLI GitClient
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jenkinsci/plugins/gitclient/GitClient.java
Expand Up @@ -8,6 +8,7 @@
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
import hudson.FilePath;
import hudson.ProxyConfiguration;
import hudson.model.TaskListener;
import hudson.plugins.git.*;
import org.eclipse.jgit.lib.ObjectId;
Expand Down Expand Up @@ -380,4 +381,6 @@ public interface GitClient {
String describe(String commitIsh) throws GitException, InterruptedException;

void setCredentials(StandardUsernameCredentials cred);

void setProxy(ProxyConfiguration proxy);
}
10 changes: 8 additions & 2 deletions src/main/java/org/jenkinsci/plugins/gitclient/RemoteGitImpl.java
Expand Up @@ -3,6 +3,7 @@
import com.cloudbees.plugins.credentials.common.StandardCredentials;
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import hudson.FilePath;
import hudson.ProxyConfiguration;
import hudson.Util;
import hudson.model.TaskListener;
import hudson.plugins.git.Branch;
Expand Down Expand Up @@ -303,7 +304,7 @@ public void fetch(String remoteName, RefSpec... refspec) throws GitException, In
}

public void fetch(String remoteName, RefSpec refspec) throws GitException, InterruptedException {
fetch(remoteName, new RefSpec[] {refspec});
fetch(remoteName, new RefSpec[]{refspec});
}

public void push(String remoteName, String refspec) throws GitException, InterruptedException {
Expand Down Expand Up @@ -527,7 +528,7 @@ public List<IndexEntry> lsTree(String treeIsh) throws GitException, InterruptedE
}

public List<IndexEntry> lsTree(String treeIsh, boolean recursive) throws GitException, InterruptedException {
return getGitAPI().lsTree(treeIsh,recursive);
return getGitAPI().lsTree(treeIsh, recursive);
}

public List<ObjectId> revListBranch(String branchId) throws GitException, InterruptedException {
Expand All @@ -542,5 +543,10 @@ public List<Tag> getTagsOnCommit(String revName) throws GitException, IOExceptio
return getGitAPI().getTagsOnCommit(revName);
}

public void setProxy(ProxyConfiguration proxyConfiguration) {
proxy.setProxy(proxyConfiguration);
}


private static final long serialVersionUID = 1L;
}

0 comments on commit 0b90466

Please sign in to comment.