Skip to content

Commit

Permalink
Prevent NPE on paths with @ in the parent.
Browse files Browse the repository at this point in the history
JENKINS-40055
  • Loading branch information
p4paul committed Jan 5, 2017
1 parent 84a13eb commit c6a01fe
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/main/java/org/jenkinsci/plugins/p4/tasks/AbstractTask.java
Expand Up @@ -102,24 +102,30 @@ public Workspace setEnvironment(Run<?, ?> run, Workspace wsType, FilePath buildW
String root = buildWorkspace.getRemote();
if (root.contains("@")) {
root = root.replace("@", "%40");
String client = ws.getFullName();
String name = buildWorkspace.getName();
}

// Template workspace for parallel execution
String name = buildWorkspace.getName();
if (name.contains("@")) {
String[] parts = name.split("@");
String exec = parts[1];
if (parts.length == 2) {
String exec = parts[1];

// Update Workspace before cloning
setWorkspace(ws);
// Update Workspace before cloning
setWorkspace(ws);

// Template workspace to .cloneN (where N is the @ number)
try {
int n = Integer.parseInt(exec);
String charset = ws.getCharset();
boolean pin = ws.isPinHost();
String template = client + ".clone" + n;
ws = new TemplateWorkspaceImpl(charset, pin, client, template);
ws.setExpand(envVars);
} catch (NumberFormatException e) {
// do not template; e.g. 'script' keeps original name
// Template workspace to .cloneN (where N is the @ number)
try {
int n = Integer.parseInt(exec);
String charset = ws.getCharset();
boolean pin = ws.isPinHost();
String fullName = ws.getFullName();
String template = fullName + ".clone" + n;
ws = new TemplateWorkspaceImpl(charset, pin, fullName, template);
ws.setExpand(envVars);
} catch (NumberFormatException e) {
// do not template; e.g. 'script' keeps original name
}
}
}
ws.setRootPath(root);
Expand Down

0 comments on commit c6a01fe

Please sign in to comment.