Skip to content

Commit

Permalink
[FIXED JENKINS-50171] Don't use package names in loadedScripts keys.
Browse files Browse the repository at this point in the history
It just makes things go badly.
  • Loading branch information
abayer committed Mar 16, 2018
1 parent a63e684 commit 73d11f2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
Expand Up @@ -110,7 +110,7 @@ public void prepareScript(Script script) {
public Script parse(GroovyCodeSource codeSource) throws CompilationFailedException {
Script s = doParse(codeSource);
if (execution!=null)
execution.loadedScripts.put(s.getClass().getName(), codeSource.getScriptText());
execution.loadedScripts.put(s.getClass().getSimpleName(), codeSource.getScriptText());
if (this.execution != null && !this.execution.getDurabilityHint().isPersistWithEveryStep()) {
// Ensure we persist new scripts
this.execution.saveOwner();
Expand Down
@@ -1,6 +1,8 @@
package org.jenkinsci.plugins.workflow.cps.steps;

import javax.inject.Inject;

import hudson.FilePath;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
Expand Down Expand Up @@ -157,4 +159,55 @@ public void pauseInsideLoad() throws Exception {
});
}

@Issue("JENKINS-50172")
@Test public void loadAndUnnamedClassesInPackage() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
FilePath pkgDir = story.j.jenkins.getWorkspaceFor(p).child("src/org/foo/devops");
pkgDir.mkdirs();
pkgDir.child("Utility.groovy").write("package org.foo.devops\n" +
"def isValueExist(String value) {\n" +
" if(value == null || value.trim().length() == 0 || value.trim().equals(\"\\\"\\\"\")) {\n" +
" return false\n" +
" }\n" +
" return true\n" +
"}\n" +
"return this;\n", null);
pkgDir.child("JenkinsEnvironment.groovy").write("package org.foo.devops\n" +
"def loadProdConfiguration() {\n" +
" def valueMap = [:]\n" +
" valueMap.put('key','value')\n" +
" return valueMap\n" +
"}\n" +
"return this;\n", null);

p.setDefinition(new CpsFlowDefinition("def util\n" +
"def config\n" +
"def util2\n" +
"node('master') {\n" +
" config = load 'src/org/foo/devops/JenkinsEnvironment.groovy'\n" +
" util = load 'src/org/foo/devops/Utility.groovy'\n" +
" config.loadProdConfiguration()\n" +
"}\n" +
"util.isValueExist(\"\")\n" +
"semaphore 'wait'\n" +
"node('master') {\n" +
" util2 = load 'src/org/foo/devops/Utility.groovy'\n" +
" util = load 'src/org/foo/devops/Utility.groovy'\n" +
"}\n", true));
WorkflowRun b = p.scheduleBuild2(0).getStartCondition().get();
SemaphoreStep.waitForStart("wait/1", b);
}
});
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
WorkflowJob p = story.j.jenkins.getItemByFullName("p", WorkflowJob.class);
WorkflowRun b = p.getBuildByNumber(1);
SemaphoreStep.success("wait/1", null);
story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b));
}
});
}

}

0 comments on commit 73d11f2

Please sign in to comment.