Skip to content

Commit

Permalink
Merge pull request #180 from jglick/pipeline-groovy-lib
Browse files Browse the repository at this point in the history
[JENKINS-57023] Switch dep from `workflow-cps-global-lib` to `pipeline-groovy-lib`
  • Loading branch information
jglick authored May 24, 2022
2 parents c169a13 + 30ccac8 commit e14ab06
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
9 changes: 5 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ THE SOFTWARE.
</pluginRepositories>
<properties>
<changelist>999999-SNAPSHOT</changelist>
<jenkins.version>2.289.1</jenkins.version>
<jenkins.version>2.303.3</jenkins.version>
<no-test-jar>false</no-test-jar>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.289.x</artifactId>
<artifactId>bom-2.303.x</artifactId>
<version>1289.v5c4b_1c43511b_</version>
<scope>import</scope>
<type>pom</type>
Expand Down Expand Up @@ -137,8 +137,9 @@ THE SOFTWARE.
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps-global-lib</artifactId>
<groupId>io.jenkins.plugins</groupId>
<artifactId>pipeline-groovy-lib</artifactId>
<version>589.vb_a_b_4a_a_8c443c</version> <!-- TODO until in BOM -->
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,26 @@

package org.jenkinsci.plugins.workflow.multibranch;

import hudson.ExtensionList;
import hudson.model.RootAction;
import hudson.FilePath;
import hudson.model.Run;
import hudson.model.TaskListener;
import java.io.File;
import java.nio.file.Files;
import java.util.Arrays;
import jenkins.branch.BranchProperty;
import jenkins.branch.BranchSource;
import jenkins.branch.DefaultBranchPropertyStrategy;
import jenkins.model.Jenkins;
import jenkins.plugins.git.GitSCMSource;
import jenkins.plugins.git.GitSampleRepoRule;
import jenkins.plugins.git.GitStep;
import org.apache.commons.io.FileUtils;
import org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition;
import org.jenkinsci.plugins.workflow.cps.global.WorkflowLibRepository;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.libs.GlobalLibraries;
import org.jenkinsci.plugins.workflow.libs.LibraryConfiguration;
import org.jenkinsci.plugins.workflow.libs.LibraryRetriever;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
import org.junit.Test;
import static org.junit.Assert.*;
Expand Down Expand Up @@ -90,8 +95,12 @@ public class SCMVarTest {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
// Set up a standardJob definition:
WorkflowLibRepository repo = ExtensionList.lookup(RootAction.class).get(WorkflowLibRepository.class);
File vars = new File(repo.workspace, /*UserDefinedGlobalVariable.PREFIX*/ "vars");
File lib = new File(Jenkins.get().getRootDir(), "somelib");
LibraryConfiguration cfg = new LibraryConfiguration("somelib", new LocalRetriever(lib));
cfg.setImplicit(true);
cfg.setDefaultVersion("fixed");
GlobalLibraries.get().setLibraries(Arrays.asList(cfg));
File vars = new File(lib, "vars");
Files.createDirectories(vars.toPath());
FileUtils.writeStringToFile(new File(vars, "standardJob.groovy"),
"def call(body) {\n" +
Expand Down Expand Up @@ -121,6 +130,20 @@ public class SCMVarTest {
});
}

// TODO copied from GrapeTest along with body of libroot(); could make sense as a *-tests.jar utility
private static final class LocalRetriever extends LibraryRetriever {
private final File lib;
LocalRetriever(File lib) {
this.lib = lib;
}
@Override public void retrieve(String name, String version, boolean changelog, FilePath target, Run<?, ?> run, TaskListener listener) throws Exception {
new FilePath(lib).copyRecursiveTo(target);
}
@Override public void retrieve(String name, String version, FilePath target, Run<?, ?> run, TaskListener listener) throws Exception {
retrieve(name, version, false, target, run, listener);
}
}

@Issue("JENKINS-31386")
@Test public void standaloneProject() {
story.addStep(new Statement() {
Expand Down

0 comments on commit e14ab06

Please sign in to comment.