Skip to content
Permalink
Browse files
[JENKINS-42817] readTrusted was producing a misleading error when usi…
…ng CpsScmFlowDefinition on an SCM rejecting lightweight checkouts.
  • Loading branch information
jglick committed Aug 3, 2017
1 parent f261fb4 commit 60417b6017779aaf4ebd5d75e25039edca4f27ec
Showing 2 changed files with 30 additions and 5 deletions.
@@ -92,6 +92,7 @@ public static class Execution extends AbstractSynchronousNonBlockingStepExecutio
SCM standaloneSCM = null;
BranchJobProperty property = job.getProperty(BranchJobProperty.class);
if (property == null) {
boolean ok = false;
if (job instanceof WorkflowJob) {
FlowDefinition defn = ((WorkflowJob) job).getDefinition();
if (defn instanceof CpsScmFlowDefinition) {
@@ -106,13 +107,18 @@ public static class Execution extends AbstractSynchronousNonBlockingStepExecutio
} catch (IOException | InterruptedException x) {
listener.error("Could not do lightweight checkout, falling back to heavyweight").println(Functions.printThrowable(x).trim());
}
} else if (!SCMBinder.USE_HEAVYWEIGHT_CHECKOUT) {
listener.getLogger().println("No lightweight checkout support in this SCM configuration");
}
}
ok = true;
}
}
throw new AbortException("‘readTrusted’ is only available when using “" +
Jenkins.getActiveInstance().getDescriptorByType(WorkflowMultiBranchProject.DescriptorImpl.class).getDisplayName() +
"” or “" + Jenkins.getActiveInstance().getDescriptorByType(CpsScmFlowDefinition.DescriptorImpl.class).getDisplayName() + "”");
if (!ok) { // wrong definition or job type
throw new AbortException("‘readTrusted’ is only available when using “" +
Jenkins.getActiveInstance().getDescriptorByType(WorkflowMultiBranchProject.DescriptorImpl.class).getDisplayName() +
"” or “" + Jenkins.getActiveInstance().getDescriptorByType(CpsScmFlowDefinition.DescriptorImpl.class).getDisplayName() + "”");
}
}
Node node = Jenkins.getActiveInstance();
FilePath dir;
@@ -166,12 +166,31 @@ public class ReadTrustedStepTest {
sampleRepo.git("commit", "--all", "--message=defined");
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
GitStep step = new GitStep(sampleRepo.toString());
step.setCredentialsId("nonexistent"); // TODO work around NPE pending https://github.com/jenkinsci/git-plugin/pull/467
p.setDefinition(new CpsScmFlowDefinition(step.createSCM(), "Jenkinsfile"));
// TODO after https://github.com/jenkinsci/workflow-cps-plugin/pull/97 could setLightweight(true)
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
r.assertLogContains("said how do you do", b);
r.assertLogContains("Obtained message from git ", b);
}

@Issue("JENKINS-42817")
@Test public void nonMultibranchHeavyweight() throws Exception {
SCMBinder.USE_HEAVYWEIGHT_CHECKOUT = true;
try {
sampleRepo.init();
sampleRepo.write("Jenkinsfile", "echo \"said ${readTrusted 'message'}\"");
sampleRepo.write("message", "how do you do");
sampleRepo.git("add", "Jenkinsfile", "message");
sampleRepo.git("commit", "--all", "--message=defined");
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
GitStep step = new GitStep(sampleRepo.toString());
CpsScmFlowDefinition def = new CpsScmFlowDefinition(step.createSCM(), "Jenkinsfile");
def.setLightweight(true);
p.setDefinition(def);
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
r.assertLogContains("said how do you do", b);
} finally {
SCMBinder.USE_HEAVYWEIGHT_CHECKOUT = false;
}
}

}

0 comments on commit 60417b6

Please sign in to comment.