Skip to content

Commit

Permalink
[JENKINS-34825] Adapt the guessBrowser method to retrieve Job from St…
Browse files Browse the repository at this point in the history
…apler request.
  • Loading branch information
Dohbedoh committed Feb 16, 2017
1 parent a70b9f2 commit d71495f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -17,7 +17,7 @@
<url>https://wiki.jenkins-ci.org/display/JENKINS/P4+Plugin</url>

<properties>
<jenkins.version>1.596.1</jenkins.version>
<jenkins.version>1.609</jenkins.version>
</properties>

<scm>
Expand Down
19 changes: 14 additions & 5 deletions src/main/java/org/jenkinsci/plugins/p4/PerforceScm.java
Expand Up @@ -55,10 +55,7 @@
import org.jenkinsci.plugins.p4.workspace.StreamWorkspaceImpl;
import org.jenkinsci.plugins.p4.workspace.TemplateWorkspaceImpl;
import org.jenkinsci.plugins.p4.workspace.Workspace;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.*;

import javax.annotation.CheckForNull;
import java.io.File;
Expand Down Expand Up @@ -218,8 +215,20 @@ public RepositoryBrowser<?> guessBrowser() {
logger.fine("No credential for perforce");
return null;
}
StaplerRequest req = Stapler.getCurrentRequest();
if (req == null) {
logger.fine("Unable to retrieve job from request");
return null;
}

Job job = req.findAncestorObject(Job.class);
if (req == null) {
logger.fine("Unable to retrieve job");
return null;
}

try {
ConnectionHelper connection = new ConnectionHelper(scmCredential, null);
ConnectionHelper connection = new ConnectionHelper(job, scmCredential, null);
String swarm = connection.getSwarm();
URL url = new URL(swarm);
return new SwarmBrowser(url);
Expand Down

0 comments on commit d71495f

Please sign in to comment.