Last active
January 20, 2020 10:03
-
-
Save daxroc/de8bce8b69fdaf767f33933c3466f850 to your computer and use it in GitHub Desktop.
Jenkins Pipeline Unit testing shared library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env groovy | |
import com.lesfurets.jenkins.unit.global.lib.Library | |
@Library("example.common@master") | |
import com.example.jenkins.agents.DeploymentAgent | |
def execute(){ | |
node() { | |
DeploymentAgent agent = new DeploymentAgent() | |
//println new DeploymentAgent().metaClass.methods*.name.sort().unique() | |
stage("Setup"){ | |
agent.example() | |
} | |
} | |
} | |
return this |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.jenkins.agents | |
void example(){ | |
echo "example running" | |
} | |
return this |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library | |
import static com.lesfurets.jenkins.unit.global.lib.LocalSource.localSource | |
import com.lesfurets.jenkins.unit.BaseRegressionTest | |
import com.lesfurets.jenkins.unit.BasePipelineTest | |
import org.junit.Before | |
import org.junit.Test | |
class TestDeploymentAgent extends BaseRegressionTest { | |
@Override | |
@Before | |
void setUp() throws Exception{ | |
helper.scriptRoots += 'src' | |
helper.scriptRoots += 'vars' | |
helper.scriptRoots += 'test' | |
helper.scriptRoots += 'jobs' | |
callStackPath = 'test/resources/callstacks/' | |
String sharedLibs = this.class.getResource('./').getFile() | |
def library = library() | |
.name('example.common') | |
.allowOverride(false) | |
.retriever(localSource(sharedLibs)) | |
.targetPath(sharedLibs) | |
.defaultVersion("master") | |
.implicit(false) | |
.build() | |
helper.registerSharedLibrary(library) | |
super.setUp() | |
} | |
@Test | |
void should_execute_without_errors() throws Exception { | |
Script script = loadScript("jobs/agent.jenkins") | |
script.execute() | |
printCallStack() | |
assertJobStatusSuccess() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment