1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-18 05:18:24 +02:00

Merge remote-tracking branch 'github/master' into HEAD

This commit is contained in:
Marcus Holl 2018-02-02 09:34:27 +01:00
commit 87f899a731
15 changed files with 152 additions and 69 deletions

View File

@ -6,9 +6,8 @@ import org.junit.rules.RuleChain
import com.lesfurets.jenkins.unit.BasePipelineTest import com.lesfurets.jenkins.unit.BasePipelineTest
import util.JenkinsConfigRule
import util.JenkinsLoggingRule import util.JenkinsLoggingRule
import util.JenkinsSetupRule import util.Rules
import static org.junit.Assert.assertEquals import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertTrue import static org.junit.Assert.assertTrue
@ -20,9 +19,8 @@ class DockerExecuteTest extends BasePipelineTest {
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this) private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
@Rule @Rule
public RuleChain ruleChain = RuleChain.outerRule(new JenkinsSetupRule(this)) public RuleChain ruleChain = RuleChain.outerRule(Rules.getCommonRules(this))
.around(jlr) .around(jlr)
.around(new JenkinsConfigRule(this))
int whichDockerReturnValue = 0 int whichDockerReturnValue = 0

View File

@ -1,14 +1,17 @@
#!groovy #!groovy
import com.lesfurets.jenkins.unit.BasePipelineTest import com.lesfurets.jenkins.unit.BasePipelineTest
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import util.JenkinsSetupRule
import static org.junit.Assert.assertTrue import static org.junit.Assert.assertTrue
import org.junit.rules.RuleChain
import util.Rules
class DurationMeasureTest extends BasePipelineTest { class DurationMeasureTest extends BasePipelineTest {
@Rule @Rule
public JenkinsSetupRule setupRule = new JenkinsSetupRule(this) public RuleChain rules = Rules.getCommonRules(this)
@Test @Test
void testDurationMeasurement() throws Exception { void testDurationMeasurement() throws Exception {

View File

@ -6,7 +6,7 @@ import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.junit.rules.RuleChain import org.junit.rules.RuleChain
import util.JenkinsLoggingRule import util.JenkinsLoggingRule
import util.JenkinsSetupRule import util.Rules
import static org.junit.Assert.assertTrue import static org.junit.Assert.assertTrue
import static org.junit.Assert.assertEquals import static org.junit.Assert.assertEquals
@ -21,13 +21,11 @@ class InfluxWriteDataTest extends BasePipelineTest {
def cpe def cpe
public JenkinsSetupRule setupRule = new JenkinsSetupRule(this)
public JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this) public JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
@Rule @Rule
public RuleChain ruleChain = public RuleChain ruleChain = Rules.getCommonRules(this)
RuleChain.outerRule(setupRule) .around(loggingRule)
.around(loggingRule)
@Before @Before
void init() throws Exception { void init() throws Exception {

View File

@ -10,10 +10,9 @@ import org.junit.rules.TemporaryFolder
import com.lesfurets.jenkins.unit.BasePipelineTest import com.lesfurets.jenkins.unit.BasePipelineTest
import util.JenkinsConfigRule
import util.JenkinsLoggingRule import util.JenkinsLoggingRule
import util.JenkinsSetupRule
import util.JenkinsShellCallRule import util.JenkinsShellCallRule
import util.Rules
public class MTABuildTest extends BasePipelineTest { public class MTABuildTest extends BasePipelineTest {
@ -23,13 +22,12 @@ public class MTABuildTest extends BasePipelineTest {
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this) private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
@Rule @Rule
public RuleChain ruleChain = public RuleChain ruleChain = Rules.getCommonRules(this)
RuleChain.outerRule(thrown) .around(thrown)
.around(tmp) .around(tmp)
.around(new JenkinsSetupRule(this))
.around(jlr) .around(jlr)
.around(jscr) .around(jscr)
.around(new JenkinsConfigRule(this))
def currentDir def currentDir
def otherDir def otherDir
@ -122,12 +120,13 @@ public class MTABuildTest extends BasePipelineTest {
binding.getVariable('env')['MTA_JAR_LOCATION'] = '/opt/mta' binding.getVariable('env')['MTA_JAR_LOCATION'] = '/opt/mta'
def newDirName = 'newDir' def newDirName = 'newDir'
def newDir = new File("${currentDir}/${newDirName}") def newDirPath = "${currentDir}/${newDirName}"
def newDir = new File(newDirPath)
newDir.mkdirs() newDir.mkdirs()
new File(newDir, 'mta.yaml') << defaultMtaYaml() new File(newDir, 'mta.yaml') << defaultMtaYaml()
helper.registerAllowedMethod('pwd', [], { newDir } ) helper.registerAllowedMethod('pwd', [], { newDirPath } )
def mtarFilePath = mtaBuildScript.call(script: [commonPipelineEnvironment: cpe], buildTarget: 'NEO') def mtarFilePath = mtaBuildScript.call(script: [commonPipelineEnvironment: cpe], buildTarget: 'NEO')

View File

@ -9,9 +9,8 @@ import com.lesfurets.jenkins.unit.BasePipelineTest
import static org.junit.Assert.assertEquals import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertTrue import static org.junit.Assert.assertTrue
import util.JenkinsConfigRule
import util.JenkinsSetupRule
import util.JenkinsShellCallRule import util.JenkinsShellCallRule
import util.Rules
class MavenExecuteTest extends BasePipelineTest { class MavenExecuteTest extends BasePipelineTest {
@ -20,9 +19,8 @@ class MavenExecuteTest extends BasePipelineTest {
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this) private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
@Rule @Rule
public RuleChain ruleChain = RuleChain.outerRule(new JenkinsSetupRule(this)) public RuleChain ruleChain = Rules.getCommonRules(this)
.around(jscr) .around(jscr)
.around(new JenkinsConfigRule(this))
def mavenExecuteScript def mavenExecuteScript
def cpe def cpe

View File

@ -10,10 +10,10 @@ import org.junit.Test
import org.junit.rules.ExpectedException import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain import org.junit.rules.RuleChain
import util.JenkinsConfigRule
import util.JenkinsLoggingRule import util.JenkinsLoggingRule
import util.JenkinsSetupRule
import util.JenkinsShellCallRule import util.JenkinsShellCallRule
import util.Rules
class NeoDeploymentTest extends BasePipelineTest { class NeoDeploymentTest extends BasePipelineTest {
@ -23,12 +23,11 @@ class NeoDeploymentTest extends BasePipelineTest {
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this) private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
@Rule @Rule
public RuleChain ruleChain = RuleChain.outerRule(thrown) public RuleChain ruleChain = Rules.getCommonRules(this)
.around(tmp) .around(thrown)
.around(new JenkinsSetupRule(this)) .around(tmp)
.around(jlr) .around(jlr)
.around(jscr) .around(jscr)
.around(new JenkinsConfigRule(this))
def workspacePath def workspacePath
def warArchiveName def warArchiveName
@ -468,4 +467,31 @@ class NeoDeploymentTest extends BasePipelineTest {
warAction: 'illegalWARAction', warAction: 'illegalWARAction',
vmSize: 'lite') vmSize: 'lite')
} }
@Test
void deployHostProvidedAsDeprecatedParameterTest() {
new File(workspacePath, archiveName) << "dummy archive"
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
archivePath: archiveName,
deployHost: "my.deploy.host.com"
)
assert jlr.log.contains("[WARNING][neoDeploy] Deprecated parameter 'deployHost' is used. This will not work anymore in future versions. Use parameter 'host' instead.")
}
@Test
void deployAccountProvidedAsDeprecatedParameterTest() {
new File(workspacePath, archiveName) << "dummy archive"
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
archivePath: archiveName,
host: "my.deploy.host.com",
deployAccount: "myAccount"
)
assert jlr.log.contains("Deprecated parameter 'deployAccount' is used. This will not work anymore in future versions. Use parameter 'account' instead.")
}
} }

View File

@ -1,8 +1,4 @@
import hudson.AbortException import util.Rules
import util.JenkinsConfigRule
import util.JenkinsSetupRule
import org.junit.rules.TemporaryFolder
import com.lesfurets.jenkins.unit.BasePipelineTest import com.lesfurets.jenkins.unit.BasePipelineTest
@ -12,14 +8,15 @@ import org.junit.Test
import org.junit.rules.ExpectedException import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain import org.junit.rules.RuleChain
import util.JenkinsReadYamlRule
class PipelineExecuteTest extends BasePipelineTest { class PipelineExecuteTest extends BasePipelineTest {
private ExpectedException thrown = new ExpectedException().none() private ExpectedException thrown = new ExpectedException().none()
@Rule @Rule
public RuleChain ruleChain = RuleChain.outerRule(thrown) public RuleChain ruleChain = Rules.getCommonRules(this)
.around(new JenkinsSetupRule(this)) .around(thrown)
.around(new JenkinsConfigRule(this))
def pipelinePath def pipelinePath
def checkoutParameters = [:] def checkoutParameters = [:]

View File

@ -1,11 +1,12 @@
import org.junit.Before import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.junit.rules.RuleChain
import org.yaml.snakeyaml.Yaml import org.yaml.snakeyaml.Yaml
import com.lesfurets.jenkins.unit.BasePipelineTest import com.lesfurets.jenkins.unit.BasePipelineTest
import util.JenkinsSetupRule import util.Rules
import static org.junit.Assert.assertEquals import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertNotNull import static org.junit.Assert.assertNotNull
@ -19,7 +20,7 @@ class SetupCommonPipelineEnvironmentTest extends BasePipelineTest {
def commonPipelineEnvironment def commonPipelineEnvironment
@Rule @Rule
public JenkinsSetupRule jsr = new JenkinsSetupRule(this) public RuleChain rules = Rules.getCommonRules(this)
@Before @Before
void init() { void init() {

View File

@ -9,24 +9,21 @@ import org.junit.rules.TemporaryFolder
import com.lesfurets.jenkins.unit.BasePipelineTest import com.lesfurets.jenkins.unit.BasePipelineTest
import util.JenkinsConfigRule
import util.JenkinsLoggingRule import util.JenkinsLoggingRule
import util.JenkinsSetupRule import util.Rules
class ToolValidateTest extends BasePipelineTest { class ToolValidateTest extends BasePipelineTest {
private ExpectedException thrown = new ExpectedException().none() private ExpectedException thrown = new ExpectedException().none()
private TemporaryFolder tmp = new TemporaryFolder() private TemporaryFolder tmp = new TemporaryFolder()
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this) private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
private JenkinsConfigRule jcr = new JenkinsConfigRule(this)
@Rule @Rule
public RuleChain ruleChain = public RuleChain ruleChain = Rules.getCommonRules(this)
RuleChain.outerRule(tmp) .around(tmp)
.around(thrown) .around(thrown)
.around(new JenkinsSetupRule(this)) .around(jlr)
.around(jlr)
.around(jcr)
private notEmptyDir private notEmptyDir

View File

@ -6,8 +6,7 @@ import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.junit.rules.ExpectedException import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain import org.junit.rules.RuleChain
import util.JenkinsLoggingRule import util.Rules
import util.JenkinsSetupRule
import util.SharedLibraryCreator import util.SharedLibraryCreator
import static org.hamcrest.Matchers.containsString import static org.hamcrest.Matchers.containsString
@ -21,7 +20,7 @@ class UtilsTest extends BasePipelineTest {
public ExpectedException exception = ExpectedException.none() public ExpectedException exception = ExpectedException.none()
@Rule @Rule
public JenkinsSetupRule setUpRule = new JenkinsSetupRule(this, SharedLibraryCreator.lazyLoadedLibrary) public RuleChain rules = Rules.getCommonRules(this, SharedLibraryCreator.lazyLoadedLibrary)
Utils utils Utils utils

View File

@ -7,12 +7,12 @@ import org.junit.runner.Description
import org.junit.runners.model.Statement import org.junit.runners.model.Statement
import org.yaml.snakeyaml.Yaml import org.yaml.snakeyaml.Yaml
class JenkinsConfigRule implements TestRule { class JenkinsReadYamlRule implements TestRule {
final BasePipelineTest testInstance final BasePipelineTest testInstance
JenkinsConfigRule(BasePipelineTest testInstance) { JenkinsReadYamlRule(BasePipelineTest testInstance) {
this.testInstance = testInstance this.testInstance = testInstance
} }
@ -25,11 +25,15 @@ class JenkinsConfigRule implements TestRule {
return new Statement() { return new Statement() {
@Override @Override
void evaluate() throws Throwable { void evaluate() throws Throwable {
testInstance.helper.registerAllowedMethod("readYaml", [Map], { Map parameters -> testInstance.helper.registerAllowedMethod("readYaml", [Map], { Map m ->
Yaml yamlParser = new Yaml() if(m.text) {
return yamlParser.load(parameters.text) return new Yaml().load(m.text)
} else if(m.file) {
throw new UnsupportedOperationException()
} else {
throw new IllegalArgumentException("Key 'text' is missing in map ${m}.")
}
}) })
DefaultValueCache.reset()
base.evaluate() base.evaluate()
} }

View File

@ -0,0 +1,34 @@
package util
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
import com.lesfurets.jenkins.unit.BasePipelineTest
import com.sap.piper.DefaultValueCache
class JenkinsResetDefaultCacheRule implements TestRule {
JenkinsResetDefaultCacheRule() {
this(null)
}
//
// Actually not needed. Only provided for the sake of consistency
// with our other rules which comes with an constructor having the
// test case contained in the signature.
JenkinsResetDefaultCacheRule(BasePipelineTest testInstance) {
}
@Override
Statement apply(Statement base, Description description) {
return new Statement() {
@Override
void evaluate() throws Throwable {
DefaultValueCache.reset()
base.evaluate()
}
}
}
}

View File

@ -13,12 +13,13 @@ class JenkinsSetupRule implements TestRule {
final BasePipelineTest testInstance final BasePipelineTest testInstance
JenkinsSetupRule(BasePipelineTest testInstance) { JenkinsSetupRule(BasePipelineTest testInstance) {
this.testInstance = testInstance this(testInstance, null)
} }
JenkinsSetupRule(BasePipelineTest testInstance, LibraryConfiguration configuration) { JenkinsSetupRule(BasePipelineTest testInstance, LibraryConfiguration configuration) {
this.testInstance = testInstance this.testInstance = testInstance
this.library = configuration if(configuration)
this.library = configuration
} }
@Override @Override

View File

@ -0,0 +1,19 @@
package util;
import org.junit.rules.RuleChain;
import com.lesfurets.jenkins.unit.BasePipelineTest;
import com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration
public class Rules {
public static RuleChain getCommonRules(BasePipelineTest testCase) {
return getCommonRules(testCase, null)
}
public static RuleChain getCommonRules(BasePipelineTest testCase, LibraryConfiguration libConfig) {
return RuleChain.outerRule(new JenkinsSetupRule(testCase, libConfig))
.around(new JenkinsReadYamlRule(testCase))
.around(new JenkinsResetDefaultCacheRule())
}
}

View File

@ -11,6 +11,8 @@ def call(parameters = [:]) {
'applicationName', 'applicationName',
'archivePath', 'archivePath',
'account', 'account',
'deployAccount', //deprecated, replaced by parameter 'account'
'deployHost', //deprecated, replaced by parameter 'host'
'deployMode', 'deployMode',
'dockerEnvVars', 'dockerEnvVars',
'dockerImage', 'dockerImage',
@ -60,14 +62,21 @@ def call(parameters = [:]) {
stepConfiguration.put('account', defaultDeployAccount) stepConfiguration.put('account', defaultDeployAccount)
} }
if(parameters.DEPLOY_HOST && !parameters.host) { if(parameters.deployHost && !parameters.host) {
echo "[WARNING][${stepName}] Deprecated parameter 'DEPLOY_HOST' is used. This will not work anymore in future versions. Use parameter 'host' instead." echo "[WARNING][${stepName}] Deprecated parameter 'deployHost' is used. This will not work anymore in future versions. Use parameter 'host' instead."
parameters.put('host', parameters.DEPLOY_HOST) parameters.put('host', parameters.deployHost)
} }
if(parameters.CI_DEPLOY_ACCOUNT && !parameters.account) { if(parameters.deployAccount && !parameters.account) {
echo "[WARNING][${stepName}] Deprecated parameter 'CI_DEPLOY_ACCOUNT' is used. This will not work anymore in future versions. Use parameter 'account' instead." echo "[WARNING][${stepName}] Deprecated parameter 'deployAccount' is used. This will not work anymore in future versions. Use parameter 'account' instead."
parameters.put('account', parameters.CI_DEPLOY_ACCOUNT) parameters.put('account', parameters.deployAccount)
}
def credId = script.commonPipelineEnvironment.getConfigProperty('neoCredentialsId')
if(credId && !parameters.neoCredentialsId) {
echo "[WARNING][${stepName}] Deprecated parameter 'neoCredentialsId' from old configuration framework is used. This will not work anymore in future versions."
parameters.put('neoCredentialsId', credId)
} }
// Backward compatibility end // Backward compatibility end