You've already forked jenkins-lib
forked from jenkins/jenkins-lib
Конфиг по умолчанию, мерж конфигураций, интеграционные тесты
This commit is contained in:
77
test/integration/groovy/jobConfigurationTest.groovy
Normal file
77
test/integration/groovy/jobConfigurationTest.groovy
Normal file
@@ -0,0 +1,77 @@
|
||||
import org.apache.commons.io.IOUtils
|
||||
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition
|
||||
import org.jenkinsci.plugins.workflow.job.WorkflowJob
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.jvnet.hudson.test.JenkinsRule
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
class jobConfigurationTest {
|
||||
|
||||
@Rule
|
||||
public JenkinsRule rule = new JenkinsRule()
|
||||
|
||||
@Before
|
||||
void configureGlobalGitLibraries() {
|
||||
RuleBootstrapper.setup(rule)
|
||||
}
|
||||
|
||||
@Test
|
||||
void "jobConfiguration should not fail without file"() {
|
||||
|
||||
def pipeline = """
|
||||
pipeline {
|
||||
agent any
|
||||
stages {
|
||||
stage('test') {
|
||||
steps {
|
||||
echo jobConfiguration().toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""".stripIndent()
|
||||
final CpsFlowDefinition flow = new CpsFlowDefinition(pipeline, true)
|
||||
final WorkflowJob workflowJob = rule.createProject(WorkflowJob, 'project')
|
||||
workflowJob.definition = flow
|
||||
|
||||
rule.buildAndAssertSuccess(workflowJob)
|
||||
}
|
||||
|
||||
@Test
|
||||
void "jobConfiguration should merge configurations"() {
|
||||
|
||||
def file = IOUtils.resourceToString(
|
||||
'jobConfiguration.json',
|
||||
StandardCharsets.UTF_8,
|
||||
this.getClass().getClassLoader()
|
||||
);
|
||||
|
||||
def writeFile = """
|
||||
writeFile text: \"\"\"$file\"\"\", file: 'jobConfiguration.json'
|
||||
"""
|
||||
|
||||
def pipeline = """
|
||||
pipeline {
|
||||
agent any
|
||||
stages {
|
||||
stage('test') {
|
||||
steps {
|
||||
$writeFile
|
||||
echo jobConfiguration().toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""".stripIndent()
|
||||
final CpsFlowDefinition flow = new CpsFlowDefinition(pipeline, true)
|
||||
final WorkflowJob workflowJob = rule.createProject(WorkflowJob, 'project')
|
||||
workflowJob.definition = flow
|
||||
|
||||
def run = rule.buildAndAssertSuccess(workflowJob)
|
||||
rule.assertLogContains('v8version=8.3.12.1500', run)
|
||||
rule.assertLogContains('sonarScannerToolName=sonar-scanner', run)
|
||||
}
|
||||
}
|
3
test/integration/resources/jobConfiguration.json
Normal file
3
test/integration/resources/jobConfiguration.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"v8version": "8.3.12.1500"
|
||||
}
|
Reference in New Issue
Block a user