Skip to content

Commit

Permalink
Merge pull request #60 from stuartrowe/master
Browse files Browse the repository at this point in the history
[FIXED JENKINS-25559] - Don't rename remote clients in concurrent builds
  • Loading branch information
oleg-nenashev committed Nov 12, 2014
2 parents 71dd14e + 27d04a7 commit b3c84d1
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions src/main/java/hudson/plugins/perforce/PerforceSCM.java
Expand Up @@ -531,8 +531,15 @@ public void buildEnvVars(@Nonnull AbstractBuild build, @Nonnull Map<String, Stri
if (p4Ticket != null) {
env.put("P4TICKET", p4Ticket);
}

env.put("P4CLIENT", getConcurrentClientName(build.getWorkspace(), getEffectiveClientName(build, env)));
// If we are running concurrent builds, the Jenkins workspace path is different
// for each concurrent build. Append Perforce workspace name with Jenkins
// workspace identifier suffix. But, only if we are syncing or allowing Jenkins to
// manage workspaces.
String effectiveP4Client = getEffectiveClientName(build, env);
if (!this.disableSyncOnly || this.createWorkspace) {
effectiveP4Client = getConcurrentClientName(build.getWorkspace(), effectiveP4Client);
}
env.put("P4CLIENT", effectiveP4Client);
} catch (ParameterSubstitutionException ex) {
LOGGER.log(MacroStringHelper.SUBSTITUTION_ERROR_LEVEL, "Cannot build environent variables due to unresolved macros", ex);
//TODO: exit?
Expand Down Expand Up @@ -1583,8 +1590,11 @@ private Workspace getPerforceWorkspace(AbstractProject project, String projectPa

// If we are running concurrent builds, the Jenkins workspace path is different
// for each concurrent build. Append Perforce workspace name with Jenkins
// workspace identifier suffix.
effectiveP4Client = getConcurrentClientName(workspace, effectiveP4Client);
// workspace identifier suffix. But, only do this if we are syncing or allowing
// Jenkins to manage workspaces.
if(!this.disableSyncOnly || this.createWorkspace) {
effectiveP4Client = getConcurrentClientName(workspace, effectiveP4Client);
}

if (!nodeIsRemote(buildNode)) {
log.print("Using master perforce client: ");
Expand Down Expand Up @@ -1699,7 +1709,7 @@ private String getEffectiveClientName(AbstractBuild build, Map<String,String> en
FilePath workspace = build.getWorkspace();
String effectiveP4Client = this.p4Client;
try {
effectiveP4Client = getEffectiveClientName(effectiveP4Client, build.getProject(), buildNode);
effectiveP4Client = getEffectiveClientName(effectiveP4Client, build);
} catch (Exception e) {
new StreamTaskListener(System.out).getLogger().println(
"Could not get effective client name: " + e.getMessage());
Expand Down Expand Up @@ -1739,7 +1749,29 @@ private String getEffectiveClientName(
effectiveP4Client = effectiveP4Client.replaceAll(" ", "_");
return effectiveP4Client;
}

private String getEffectiveClientName(
@Nonnull String basename,
@CheckForNull AbstractBuild build)
throws IOException, InterruptedException {

String effectiveP4Client = basename;
if(build != null) {
Node buildNode = build.getBuiltOn();

//TODO: Seems that local node should be handled as well
if (buildNode!=null && nodeIsRemote(buildNode) && !getSlaveClientNameFormat().equals("")) {

Map<String, String> additionalSubstitutions = build.getBuildVariables();
effectiveP4Client = MacroStringHelper.substituteParameters (
getSlaveClientNameFormat(), this, build.getProject(), buildNode, additionalSubstitutions);
}
// eliminate spaces, just in case
effectiveP4Client = effectiveP4Client.replaceAll(" ", "_");
}
return effectiveP4Client;
}

public String getSlaveClientNameFormat() {
if (this.slaveClientNameFormat == null || this.slaveClientNameFormat.equals("")) {
if (this.dontRenameClient) {
Expand Down

0 comments on commit b3c84d1

Please sign in to comment.