Skip to content
Permalink
Browse files

Merge pull request #131 from recena/JENKINS-29340

[JENKINS-29340] ISVNAuthentication provider did not provide credentials (part. II)
  • Loading branch information
recena committed Aug 19, 2015
2 parents 2e95528 + d89f530 commit b029f4086567971b1f9fa736d6d10679c27650a3
Showing with 77 additions and 24 deletions.
  1. +6 −0 pom.xml
  2. +27 −24 src/main/java/hudson/scm/SubversionSCM.java
  3. +44 −0 src/test/java/hudson/scm/SubversionEnvInjectTest.java
@@ -143,6 +143,12 @@ THE SOFTWARE.
<version>1.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>envinject</artifactId>
<version>1.92</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jenkins-ci.main</groupId>
@@ -78,6 +78,7 @@
import java.util.LinkedHashSet;
import java.util.WeakHashMap;

import hudson.remoting.LocalChannel;
import hudson.security.ACL;
import hudson.util.ListBoxModel;
import jenkins.model.Jenkins;
@@ -1332,11 +1333,9 @@ public PollingResult compareRemoteRevisionWith(Job<?,?> project, Launcher launch
final SVNRevisionState baseline;
if (_baseline instanceof SVNRevisionState) {
baseline = (SVNRevisionState)_baseline;
}
else if (project.getLastBuild()!=null) {
} else if (project.getLastBuild()!=null) {
baseline = (SVNRevisionState)calcRevisionsFromBuild(project.getLastBuild(), launcher != null ? workspace : null, launcher, listener);
}
else {
} else {
baseline = new SVNRevisionState(null);
}

@@ -1354,9 +1353,8 @@ else if (project.getLastBuild()!=null) {
}
if (project instanceof AbstractProject && repositoryLocationsNoLongerExist(lastCompletedBuild, listener, env)) {
// Disable this project, see HUDSON-763
listener.getLogger().println(
Messages.SubversionSCM_pollChanges_locationsNoLongerExist(project));
disableProject((AbstractProject) project, listener);
listener.getLogger().println(Messages.SubversionSCM_pollChanges_locationsNoLongerExist(project));
disableProject((AbstractProject) project, listener);
return NO_CHANGES;
}

@@ -1371,34 +1369,40 @@ else if (project.getLastBuild()!=null) {
return BUILD_NOW;
}
if (!baseline.revisions.containsKey(url)) {
listener.getLogger().println(
Messages.SubversionSCM_pollChanges_locationNotInWorkspace(url));
listener.getLogger().println(Messages.SubversionSCM_pollChanges_locationNotInWorkspace(url));
return BUILD_NOW;
}
}
}

// determine where to perform polling. prefer the node where the build happened,
// in case a cluster is non-uniform. see http://www.nabble.com/svn-connection-from-slave-only-td24970587.html
VirtualChannel ch=null;
String nodeName = "master";
VirtualChannel channel = null;
if (workspace != null && !isPollFromMaster()) {
ch = workspace.getChannel();
channel = workspace.getChannel();
if (channel != null && channel instanceof Channel) {
nodeName = ((Channel) channel).getName();
}
}
if (ch==null) ch= MasterComputer.localChannel;

final String nodeName = ch instanceof Channel ? ((Channel) ch).getName() : "master";
if (channel == null) {
channel = FilePath.localChannel;
}

final SVNLogHandler logHandler = new SVNLogHandler(createSVNLogFilter(), listener);

final Map<String,ISVNAuthenticationProvider> authProviders = new LinkedHashMap<String,
ISVNAuthenticationProvider>();
final Map<String,ISVNAuthenticationProvider> authProviders = new LinkedHashMap<String, ISVNAuthenticationProvider>();

EnvVars env = null;
Run<?,?> run = project.getLastCompletedBuild();
if (run != null) {
env = run.getEnvironment(listener);
Node node;
if (nodeName.equals("master")) {
node = Jenkins.getInstance();
} else {
node = Jenkins.getInstance().getNode(nodeName);
}

// Reference: https://github.com/jenkinsci/subversion-plugin/pull/131
// Right way to get the environment variables when we do polling. http://tinyurl.com/o2o2kg9
EnvVars env = project.getEnvironment(node, listener);

for (ModuleLocation loc: getLocations(env, null)) {
String url;
try {
@@ -1412,7 +1416,7 @@ else if (project.getLastBuild()!=null) {
final ISVNAuthenticationProvider defaultAuthProvider = createAuthenticationProvider(project, null);

// figure out the remote revisions
return ch.call(new CompareAgainstBaselineCallable(baseline, logHandler, project.getName(), listener, defaultAuthProvider, authProviders, nodeName));
return channel.call(new CompareAgainstBaselineCallable(baseline, logHandler, project.getName(), listener, defaultAuthProvider, authProviders, nodeName));
}

public SVNLogFilter createSVNLogFilter() {
@@ -2986,8 +2990,7 @@ public ModuleLocation getExpandedLocation(Job<?, ?> project) {
}
}

return new ModuleLocation(returnURL, credentialsId, getLocalDir(), getDepthOption(),
isIgnoreExternalsOption());
return new ModuleLocation(returnURL, credentialsId, getLocalDir(), getDepthOption(), isIgnoreExternalsOption());
}

@Extension
@@ -0,0 +1,44 @@
package hudson.scm;

import hudson.model.FreeStyleProject;
import hudson.model.TaskListener;
import org.jenkinsci.plugins.envinject.EnvInjectJobProperty;
import org.jenkinsci.plugins.envinject.EnvInjectJobPropertyInfo;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

import static org.junit.Assert.assertTrue;

public class SubversionEnvInjectTest {

public static String REPO_URL = "https://svn.jenkins-ci.org/trunk/hudson/test-projects/${REPO}";

@Rule
public JenkinsRule jenkins = new JenkinsRule();

/**
* This test aims to verify that the variables defined in the "Properties Content" field, are availables in SCM Polling.
*/
@Issue("JENKINS-29340")
@Test
public void pollingWithEnvInject() throws Exception {
FreeStyleProject project = jenkins.createFreeStyleProject();

EnvInjectJobPropertyInfo jobPropertyInfo = new EnvInjectJobPropertyInfo(null, "REPO=trivial-maven", null, null, null, false);
EnvInjectJobProperty envInjectJobProperty = new EnvInjectJobProperty();
envInjectJobProperty.setOn(true);
envInjectJobProperty.setInfo(jobPropertyInfo);
project.addProperty(envInjectJobProperty);

project.setScm(new SubversionSCM(REPO_URL));

TaskListener listener = jenkins.createTaskListener();
PollingResult poll = project.poll(listener);
// If true means that parameters have been replaced correctly and we have a valid repository URL.
assertTrue(poll.hasChanges());

jenkins.assertBuildStatusSuccess(project.scheduleBuild2(0).get());
}
}

0 comments on commit b029f40

Please sign in to comment.
You can’t perform that action at this time.