1
0
mirror of https://github.com/firstBitMarksistskaya/jenkins-lib.git synced 2025-08-25 20:09:25 +02:00

Переезд на градль-рельсы с тестами и объектами

This commit is contained in:
Nikita Gryzlov
2020-03-26 17:04:42 +03:00
parent 39acf5efb0
commit fa208d78ef
14 changed files with 334 additions and 15 deletions

View File

@@ -0,0 +1,25 @@
import com.mkobit.jenkins.pipelines.codegen.LocalLibraryRetriever
import org.jenkinsci.plugins.workflow.libs.GlobalLibraries
import org.jenkinsci.plugins.workflow.libs.LibraryConfiguration
import org.jenkinsci.plugins.workflow.libs.LibraryRetriever
import org.jvnet.hudson.test.JenkinsRule
final class RuleBootstrapper {
private RuleBootstrapper() {
}
/**
* This demonstrates how you can can configure the {@link JenkinsRule} to use the local source code
* as a {@link LibraryConfiguration}. In this example we are making it implicitly loaded.
*/
static void setup(JenkinsRule rule) {
rule.timeout = 30
final LibraryRetriever retriever = new LocalLibraryRetriever()
final LibraryConfiguration localLibrary =
new LibraryConfiguration('testLibrary', retriever)
localLibrary.implicit = true
localLibrary.defaultVersion = 'unused'
localLibrary.allowVersionOverride = false
GlobalLibraries.get().libraries = [localLibrary]
}
}

View File

@@ -0,0 +1,39 @@
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition
import org.jenkinsci.plugins.workflow.job.WorkflowJob
import org.jenkinsci.plugins.workflow.job.WorkflowRun
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.jvnet.hudson.test.JenkinsRule
class cmdTest {
@Rule
public JenkinsRule rule = new JenkinsRule()
@Before
void configureGlobalGitLibraries() {
RuleBootstrapper.setup(rule)
}
@Test
void "cmd should echo something"() {
def pipeline = '''
pipeline {
agent any
stages {
stage('test') {
steps {
cmd("echo helloWorld")
}
}
}
}
'''.stripIndent()
final CpsFlowDefinition flow = new CpsFlowDefinition(pipeline, true)
final WorkflowJob workflowJob = rule.createProject(WorkflowJob, 'project')
workflowJob.definition = flow
rule.assertLogContains('helloWorld', rule.buildAndAssertSuccess(workflowJob))
}
}