|
24 | 24 |
|
25 | 25 | package org.jenkinsci.plugins.workflow.multibranch;
|
26 | 26 |
|
27 |
| -import hudson.ExtensionList; |
28 |
| -import hudson.model.RootAction; |
| 27 | +import hudson.FilePath; |
| 28 | +import hudson.model.Run; |
| 29 | +import hudson.model.TaskListener; |
29 | 30 | import java.io.File;
|
30 | 31 | import java.nio.file.Files;
|
| 32 | +import java.util.Arrays; |
31 | 33 | import jenkins.branch.BranchProperty;
|
32 | 34 | import jenkins.branch.BranchSource;
|
33 | 35 | import jenkins.branch.DefaultBranchPropertyStrategy;
|
| 36 | +import jenkins.model.Jenkins; |
34 | 37 | import jenkins.plugins.git.GitSCMSource;
|
35 | 38 | import jenkins.plugins.git.GitSampleRepoRule;
|
36 | 39 | import jenkins.plugins.git.GitStep;
|
37 | 40 | import org.apache.commons.io.FileUtils;
|
38 | 41 | import org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition;
|
39 |
| -import org.jenkinsci.plugins.workflow.cps.global.WorkflowLibRepository; |
40 | 42 | import org.jenkinsci.plugins.workflow.job.WorkflowJob;
|
41 | 43 | import org.jenkinsci.plugins.workflow.job.WorkflowRun;
|
| 44 | +import org.jenkinsci.plugins.workflow.libs.GlobalLibraries; |
| 45 | +import org.jenkinsci.plugins.workflow.libs.LibraryConfiguration; |
| 46 | +import org.jenkinsci.plugins.workflow.libs.LibraryRetriever; |
42 | 47 | import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
|
43 | 48 | import org.junit.Test;
|
44 | 49 | import static org.junit.Assert.*;
|
@@ -90,8 +95,12 @@ public class SCMVarTest {
|
90 | 95 | story.addStep(new Statement() {
|
91 | 96 | @Override public void evaluate() throws Throwable {
|
92 | 97 | // Set up a standardJob definition:
|
93 |
| - WorkflowLibRepository repo = ExtensionList.lookup(RootAction.class).get(WorkflowLibRepository.class); |
94 |
| - File vars = new File(repo.workspace, /*UserDefinedGlobalVariable.PREFIX*/ "vars"); |
| 98 | + File lib = new File(Jenkins.get().getRootDir(), "somelib"); |
| 99 | + LibraryConfiguration cfg = new LibraryConfiguration("somelib", new LocalRetriever(lib)); |
| 100 | + cfg.setImplicit(true); |
| 101 | + cfg.setDefaultVersion("fixed"); |
| 102 | + GlobalLibraries.get().setLibraries(Arrays.asList(cfg)); |
| 103 | + File vars = new File(lib, "vars"); |
95 | 104 | Files.createDirectories(vars.toPath());
|
96 | 105 | FileUtils.writeStringToFile(new File(vars, "standardJob.groovy"),
|
97 | 106 | "def call(body) {\n" +
|
@@ -121,6 +130,20 @@ public class SCMVarTest {
|
121 | 130 | });
|
122 | 131 | }
|
123 | 132 |
|
| 133 | + // TODO copied from GrapeTest along with body of libroot(); could make sense as a *-tests.jar utility |
| 134 | + private static final class LocalRetriever extends LibraryRetriever { |
| 135 | + private final File lib; |
| 136 | + LocalRetriever(File lib) { |
| 137 | + this.lib = lib; |
| 138 | + } |
| 139 | + @Override public void retrieve(String name, String version, boolean changelog, FilePath target, Run<?, ?> run, TaskListener listener) throws Exception { |
| 140 | + new FilePath(lib).copyRecursiveTo(target); |
| 141 | + } |
| 142 | + @Override public void retrieve(String name, String version, FilePath target, Run<?, ?> run, TaskListener listener) throws Exception { |
| 143 | + retrieve(name, version, false, target, run, listener); |
| 144 | + } |
| 145 | + } |
| 146 | + |
124 | 147 | @Issue("JENKINS-31386")
|
125 | 148 | @Test public void standaloneProject() {
|
126 | 149 | story.addStep(new Statement() {
|
|
0 commit comments