Use ProjectSource and LocalSource retrievers
masterWhen testing shared libraries, you can use different SourceRetriever implementations depending on your goal:
- ProjectSource: Best for testing the library itself. It loads files directly from the project root (where
srcandvarsfolders reside). UseprojectSource()with no arguments to point to the current project root. - LocalSource: Best for verifying integration with existing pipelines. It allows you to use pre-copied library files from a specific directory. The retriever assumes files are located at
{path}/{libraryName}@{version}.
Example of projectSource usage:
import static com.lesfurets.jenkins.unit.global.lib.ProjectSource.projectSource
// ... inside setUp ...
Object library = library()
.name('commons')
.defaultVersion('<notNeeded>')
.allowOverride(true)
.implicit(true)
.targetPath('<notNeeded>')
.retriever(projectSource())
.build()
helper.registerSharedLibrary(library)import static com.lesfurets.jenkins.unit.global.lib.ProjectSource.projectSource
class TestCase extends BasePipelineTest {
@Override
@BeforeEach
void setUp() {
super.setUp()
Object library = library()
.name('commons')
.defaultVersion('<notNeeded>')
.allowOverride(true)
.implicit(true)
.targetPath('<notNeeded>')
.retriever(projectSource())
.build()
helper.registerSharedLibrary(library)
}
}