From dfd74faa8ca11e2ec8358e3452bd7f8d7e520360 Mon Sep 17 00:00:00 2001 From: Stanislav Ovchar Date: Sun, 8 Dec 2019 02:53:57 +0300 Subject: [PATCH] Use project source retriever --- build.gradle | 3 ++- test/com/example/TestCase1.groovy | 26 +++++++++++--------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/build.gradle b/build.gradle index 733f482..11a777f 100644 --- a/build.gradle +++ b/build.gradle @@ -5,12 +5,13 @@ apply plugin: 'groovy' repositories { mavenCentral() + maven { url 'https://repo.jenkins-ci.org/releases/' } } dependencies { compile 'org.codehaus.groovy:groovy-all:2.4.6' testCompile 'junit:junit:4.12' - testCompile files('C:\\Users\\jim\\Code\\JenkinsPipelineUnit\\build\\libs\\jenkins-pipeline-unit-1.2-SNAPSHOT.jar') + testCompile group:'com.lesfurets', name:'jenkins-pipeline-unit', version:'1.2' testCompile 'commons-io:commons-io:2.5' testCompile 'com.cloudbees:groovy-cps:1.12' testCompile 'org.slf4j:slf4j-simple:1.7.25' diff --git a/test/com/example/TestCase1.groovy b/test/com/example/TestCase1.groovy index f930c99..8d7b8e6 100644 --- a/test/com/example/TestCase1.groovy +++ b/test/com/example/TestCase1.groovy @@ -5,26 +5,22 @@ import org.junit.Test import com.lesfurets.jenkins.unit.BasePipelineTest import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library -import static com.lesfurets.jenkins.unit.global.lib.LocalSource.localSource +import static com.lesfurets.jenkins.unit.global.lib.ProjectSource.projectSource class TestCase1 extends BasePipelineTest { @Override @Before void setUp() throws Exception { - // TODO: Find a better way of getting project root dir - String dirPath = new File( System.getProperty("user.dir") ) - .getAbsoluteFile() - .getParentFile() - .getAbsolutePath() - - def library = library() - .name('jenkinslib-example') - .allowOverride(true) - .implicit(false) - .targetPath(dirPath) - .retriever(localSource(dirPath)) - .build() + + def library = library() + .name('jenkinslib-example') + .defaultVersion('') + .allowOverride(true) + .implicit(false) + .targetPath('') + .retriever(projectSource()) + .build() helper.registerSharedLibrary(library) super.setUp() @@ -32,7 +28,7 @@ class TestCase1 extends BasePipelineTest { @Test void should_run_example_pipeline_without_errors() throws Exception { - def script = loadScript("test\\resources\\pipelines\\example1.pipeline") + def script = loadScript("test/resources/pipelines/example1.pipeline") script.execute() printCallStack() }