Skip to content

Commit

Permalink
[JENKINS-31067] Global environment variables are not available on Sub…
Browse files Browse the repository at this point in the history
…version Polling
  • Loading branch information
recena committed Oct 23, 2015
1 parent 5da9ddb commit bc59039
Showing 1 changed file with 41 additions and 39 deletions.
80 changes: 41 additions & 39 deletions src/main/java/hudson/scm/SubversionSCM.java
Expand Up @@ -1329,43 +1329,67 @@ void setPollFromMaster(boolean pollFromMaster) {
}

@Override
public PollingResult compareRemoteRevisionWith(Job<?,?> project, Launcher launcher, FilePath workspace, final TaskListener listener, SCMRevisionState _baseline) throws IOException, InterruptedException {
public PollingResult compareRemoteRevisionWith(Job<?, ?> project, Launcher launcher, FilePath workspace, final
TaskListener listener, SCMRevisionState _baseline) throws IOException, InterruptedException {

final SVNRevisionState baseline;
if (_baseline instanceof SVNRevisionState) {
baseline = (SVNRevisionState)_baseline;
} else if (project.getLastBuild()!=null) {
baseline = (SVNRevisionState)calcRevisionsFromBuild(project.getLastBuild(), launcher != null ? workspace : null, launcher, listener);
baseline = (SVNRevisionState) _baseline;
} else if (project.getLastBuild() != null) {
baseline = (SVNRevisionState) calcRevisionsFromBuild(project.getLastBuild(), launcher != null ? workspace
: null, launcher, listener);
} else {
baseline = new SVNRevisionState(null);
}

// The job was never built before
if (project.getLastBuild() == null) {
listener.getLogger().println(Messages.SubversionSCM_pollChanges_noBuilds());
return BUILD_NOW;
}

Run<?,?> lastCompletedBuild = project.getLastCompletedBuild();

if (lastCompletedBuild!=null) {
EnvVars env = lastCompletedBuild.getEnvironment(listener);
if (lastCompletedBuild instanceof AbstractBuild) {
EnvVarsUtils.overrideAll(env, ((AbstractBuild) lastCompletedBuild).getBuildVariables());
String nodeName = "master";
VirtualChannel channel = null;
if (workspace != null && !isPollFromMaster()) {
channel = workspace.getChannel();
if (channel != null && channel instanceof Channel) {
nodeName = ((Channel) channel).getName();
}
}

if (channel == null) {
channel = FilePath.localChannel;
}

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);

Run<?, ?> lastCompletedBuild = project.getLastCompletedBuild();

if (lastCompletedBuild != 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);
return NO_CHANGES;
}

// are the locations checked out in the workspace consistent with the current configuration?
// Are the locations checked out in the workspace consistent with the current configuration?
for (ModuleLocation loc : getLocations(env, lastCompletedBuild)) {
// baseline.revisions has URIdecoded URL
String url;
try {
url = loc.getSVNURL().toDecodedString();
} catch (SVNException ex) {
ex.printStackTrace(listener.error(Messages.SubversionSCM_pollChanges_exception(loc.getURL())));
listener.error(Messages.SubversionSCM_pollChanges_exception(loc.getURL()));
return BUILD_NOW;
}
if (!baseline.revisions.containsKey(url)) {
Expand All @@ -1375,35 +1399,12 @@ public PollingResult compareRemoteRevisionWith(Job<?,?> project, Launcher launch
}
}

String nodeName = "master";
VirtualChannel channel = null;
if (workspace != null && !isPollFromMaster()) {
channel = workspace.getChannel();
if (channel != null && channel instanceof Channel) {
nodeName = ((Channel) channel).getName();
}
}

if (channel == null) {
channel = FilePath.localChannel;
}

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

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

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);
final Map<String, ISVNAuthenticationProvider> authProviders = new LinkedHashMap<String,
ISVNAuthenticationProvider>();

for (ModuleLocation loc: getLocations(env, null)) {
for (ModuleLocation loc : getLocations(env, null)) {
String url;
try {
url = loc.getExpandedLocation(project).getSVNURL().toDecodedString();
Expand All @@ -1416,7 +1417,8 @@ public PollingResult compareRemoteRevisionWith(Job<?,?> project, Launcher launch
final ISVNAuthenticationProvider defaultAuthProvider = createAuthenticationProvider(project, null);

// figure out the remote revisions
return channel.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() {
Expand Down

0 comments on commit bc59039

Please sign in to comment.