Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #67 from jglick/readTrusted-heavyweight-JENKINS-42817
[JENKINS-42817] readTrusted broke with CpsScmFlowDefinition & heavyweight checkouts
  • Loading branch information
abayer committed Aug 3, 2017
2 parents f261fb4 + 60417b6 commit c49261f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
Expand Up @@ -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 c49261f

Please sign in to comment.