Skip to content

Commit

Permalink
[JENKINS-33273] Release resources
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenc committed Jan 16, 2017
1 parent 02877f7 commit 8431c36
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 42 deletions.
Expand Up @@ -97,14 +97,17 @@ public static class Execution extends AbstractSynchronousNonBlockingStepExecutio
if (defn instanceof CpsScmFlowDefinition) {
// JENKINS-31386: retrofit to work with standalone projects, without doing any trust checks.
standaloneSCM = ((CpsScmFlowDefinition) defn).getScm();
SCMFileSystem fs = SCMFileSystem.of(job, standaloneSCM);
if (fs != null) { // JENKINS-33273
try {
String text = fs.child(step.path).contentAsString();
listener.getLogger().println("Obtained " + step.path + " from " + standaloneSCM.getKey());
return text;
} catch (IOException | InterruptedException x) {
listener.error("Could not do lightweight checkout, falling back to heavyweight").println(Functions.printThrowable(x).trim());
try (SCMFileSystem fs = SCMFileSystem.of(job, standaloneSCM)) {
if (fs != null) { // JENKINS-33273
try {
String text = fs.child(step.path).contentAsString();
listener.getLogger()
.println("Obtained " + step.path + " from " + standaloneSCM.getKey());
return text;
} catch (IOException | InterruptedException x) {
listener.error("Could not do lightweight checkout, falling back to heavyweight")
.println(Functions.printThrowable(x).trim());
}
}
}
}
Expand Down Expand Up @@ -169,35 +172,36 @@ public static class Execution extends AbstractSynchronousNonBlockingStepExecutio
boolean trustCheck = !tip.equals(trusted);
String untrustedFile = null;
String content;
SCMFileSystem tipFS = trustCheck ? SCMFileSystem.of(scmSource, head, tip) : null;
SCMFileSystem trustedFS = SCMFileSystem.of(scmSource, head, trusted);
if (trustedFS != null && (!trustCheck || tipFS != null)) {
if (trustCheck) {
untrustedFile = tipFS.child(step.path).contentAsString();
}
content = trustedFS.child(step.path).contentAsString();
listener.getLogger().println("Obtained " + step.path + " from " + trusted);
} else {
listener.getLogger().println("Checking out " + head.getName() + " to read " + step.path);
try (WorkspaceList.Lease lease = computer.getWorkspaceList().acquire(dir)) {
try (SCMFileSystem tipFS = trustCheck ? SCMFileSystem.of(scmSource, head, tip) : null;
SCMFileSystem trustedFS = SCMFileSystem.of(scmSource, head, trusted)) {
if (trustedFS != null && (!trustCheck || tipFS != null)) {
if (trustCheck) {
SCMStep delegate = new GenericSCMStep(scmSource.build(head, tip));
delegate.setPoll(false);
delegate.setChangelog(false);
untrustedFile = tipFS.child(step.path).contentAsString();
}
content = trustedFS.child(step.path).contentAsString();
listener.getLogger().println("Obtained " + step.path + " from " + trusted);
} else {
listener.getLogger().println("Checking out " + head.getName() + " to read " + step.path);
try (WorkspaceList.Lease lease = computer.getWorkspaceList().acquire(dir)) {
if (trustCheck) {
SCMStep delegate = new GenericSCMStep(scmSource.build(head, tip));
delegate.setPoll(false);
delegate.setChangelog(false);
delegate.checkout(build, dir, listener, node.createLauncher(listener));
if (!file.exists()) {
throw new AbortException(file + " not found");
}
untrustedFile = file.readToString();
}
SCMStep delegate = new GenericSCMStep(scmSource.build(head, trusted));
delegate.setPoll(true);
delegate.setChangelog(true);
delegate.checkout(build, dir, listener, node.createLauncher(listener));
if (!file.exists()) {
throw new AbortException(file + " not found");
}
untrustedFile = file.readToString();
}
SCMStep delegate = new GenericSCMStep(scmSource.build(head, trusted));
delegate.setPoll(true);
delegate.setChangelog(true);
delegate.checkout(build, dir, listener, node.createLauncher(listener));
if (!file.exists()) {
throw new AbortException(file + " not found");
content = file.readToString();
}
content = file.readToString();
}
}
if (trustCheck && !untrustedFile.equals(content)) {
Expand Down
Expand Up @@ -81,17 +81,20 @@ class SCMBinder extends FlowDefinition {
if (tip != null) {
build.addAction(new SCMRevisionAction(tip));
SCMRevision rev = scmSource.getTrustedRevision(tip, listener);
SCMFileSystem fs = SCMFileSystem.of(scmSource, head, rev);
if (fs != null) { // JENKINS-33273
String script = null;
try {
script = fs.child(WorkflowBranchProjectFactory.SCRIPT).contentAsString();
listener.getLogger().println("Obtained " + WorkflowBranchProjectFactory.SCRIPT + " from " + rev);
} catch (IOException | InterruptedException x) {
listener.error("Could not do lightweight checkout, falling back to heavyweight").println(Functions.printThrowable(x).trim());
}
if (script != null) {
return new CpsFlowDefinition(script, true).create(handle, listener, actions);
try (SCMFileSystem fs = SCMFileSystem.of(scmSource, head, rev)) {
if (fs != null) { // JENKINS-33273
String script = null;
try {
script = fs.child(WorkflowBranchProjectFactory.SCRIPT).contentAsString();
listener.getLogger()
.println("Obtained " + WorkflowBranchProjectFactory.SCRIPT + " from " + rev);
} catch (IOException | InterruptedException x) {
listener.error("Could not do lightweight checkout, falling back to heavyweight")
.println(Functions.printThrowable(x).trim());
}
if (script != null) {
return new CpsFlowDefinition(script, true).create(handle, listener, actions);
}
}
}
scm = scmSource.build(head, rev);
Expand Down

0 comments on commit 8431c36

Please sign in to comment.