mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-20 05:19:40 +02:00
validate JAVA if it is in PATH
This commit is contained in:
parent
66c60b4f26
commit
f29734c6da
@ -227,27 +227,6 @@ public class MtaBuildTest extends BasePipelineTest {
|
||||
}
|
||||
|
||||
|
||||
@Ignore('Tool validation disabled since it does not work properly in conjunction with slaves.')
|
||||
@Test
|
||||
void toolJavaValidateCalled() {
|
||||
|
||||
jsr.step.call(buildTarget: 'NEO')
|
||||
|
||||
assert toolJavaValidateCalled
|
||||
}
|
||||
|
||||
|
||||
@Ignore('Tool validation disabled since it does not work properly in conjunction with slaves.')
|
||||
@Test
|
||||
void toolValidateNotCalledWhenJavaHomeIsUnsetButJavaIsInPath() {
|
||||
|
||||
jscr.setReturnValue('which java', 0)
|
||||
jsr.step.call(buildTarget: 'NEO')
|
||||
|
||||
assert !toolJavaValidateCalled
|
||||
assert jlr.log.contains('Tool validation (java) skipped. JAVA_HOME not set, but java executable in path.')
|
||||
}
|
||||
|
||||
private static defaultMtaYaml() {
|
||||
return '''
|
||||
_schema-version: "2.0.0"
|
||||
|
@ -42,8 +42,6 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
.around(jsr)
|
||||
.around(jer)
|
||||
|
||||
private toolJavaValidateCalled
|
||||
|
||||
private static workspacePath
|
||||
private static warArchiveName
|
||||
private static propertiesFileName
|
||||
@ -89,8 +87,6 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
helper.registerAllowedMethod('sh', [Map], { Map m -> getVersionWithEnvVars(m) })
|
||||
|
||||
jer.env.configuration = [steps:[neoDeploy: [host: 'test.deploy.host.com', account: 'trialuser123']]]
|
||||
|
||||
toolJavaValidateCalled = false
|
||||
}
|
||||
|
||||
|
||||
@ -442,31 +438,6 @@ class NeoDeployTest extends BasePipelineTest {
|
||||
}
|
||||
|
||||
|
||||
@Ignore('Tool validation disabled since it does not work properly in conjunction with slaves.')
|
||||
@Test
|
||||
void toolJavaValidateCalled() {
|
||||
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
archivePath: archiveName,
|
||||
neoCredentialsId: 'myCredentialsId')
|
||||
|
||||
assert toolJavaValidateCalled
|
||||
}
|
||||
|
||||
@Ignore('Tool validation disabled since it does not work properly in conjunction with slaves.')
|
||||
@Test
|
||||
void toolValidateSkippedIfJavaHomeNotSetButJavaInPath() {
|
||||
|
||||
jscr.setReturnValue('which java', 0)
|
||||
jsr.step.envProps = [:] // make sure we are not confused by JAVA_HOME in current env props.
|
||||
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
|
||||
archivePath: archiveName,
|
||||
neoCredentialsId: 'myCredentialsId')
|
||||
|
||||
assert ! toolJavaValidateCalled
|
||||
assert jlr.log.contains('Skipping tool validate check (java). Java executable in path, but no JAVA_HOME found.')
|
||||
}
|
||||
|
||||
private getVersionWithEnvVars(Map m) {
|
||||
|
||||
if(m.script.contains('java -version')) {
|
||||
|
@ -4,8 +4,6 @@ import com.sap.piper.tools.Tool
|
||||
import com.sap.piper.tools.ToolVerifier
|
||||
import com.sap.piper.tools.ToolUtils
|
||||
|
||||
import groovy.transform.Field
|
||||
|
||||
|
||||
def call(Map parameters = [:]) {
|
||||
|
||||
@ -37,21 +35,8 @@ def call(Map parameters = [:]) {
|
||||
def mta = new Tool('SAP Multitarget Application Archive Builder', 'MTA_JAR_LOCATION', 'mtaJarLocation', '/', 'mta.jar', '1.0.6', '-v')
|
||||
ToolVerifier.verifyToolVersion(mta, this, configuration)
|
||||
|
||||
JAVA_HOME_CHECK : {
|
||||
|
||||
// in case JAVA_HOME is not set, but java is in the path we should not fail
|
||||
// in order to be backward compatible. Before introducing that check here
|
||||
// is worked also in case JAVA_HOME was not set, but java was in the path.
|
||||
// toolValidate works only upon JAVA_HOME and fails in case it is not set.
|
||||
|
||||
def rc = sh script: 'which java' , returnStatus: true
|
||||
if(script.JAVA_HOME || (!script.JAVA_HOME && rc != 0)) {
|
||||
def java = new Tool('Java', 'JAVA_HOME', '', '/bin/', 'java', '1.8.0', '-version 2>&1')
|
||||
ToolVerifier.verifyToolVersion(java, this, configuration)
|
||||
} else {
|
||||
echo 'Tool validation (java) skipped. JAVA_HOME not set, but java executable in path.'
|
||||
}
|
||||
}
|
||||
def java = new Tool('Java', 'JAVA_HOME', '', '/bin/', 'java', '1.8.0', '-version 2>&1')
|
||||
ToolVerifier.verifyToolVersion(java, this, configuration)
|
||||
|
||||
def mtaYmlName = "${pwd()}/mta.yaml"
|
||||
def applicationName = configuration.applicationName
|
||||
|
@ -1,7 +1,5 @@
|
||||
import com.sap.piper.Utils
|
||||
|
||||
import groovy.transform.Field
|
||||
|
||||
import com.sap.piper.ConfigurationLoader
|
||||
import com.sap.piper.ConfigurationMerger
|
||||
import com.sap.piper.ConfigurationType
|
||||
@ -10,14 +8,6 @@ import com.sap.piper.tools.ToolVerifier
|
||||
import com.sap.piper.tools.ToolUtils
|
||||
|
||||
|
||||
//
|
||||
// envProps may be overwritten by tests, but only by tests.
|
||||
// [Q] Why not simply using the Map returned by getenv() itself?
|
||||
// [A] The unmodifiable map returned by getenv() is not serializable
|
||||
// Since everythings needs to be serializabe (CPS pattern) we
|
||||
// cannot use that map directly.
|
||||
@Field Map envProps = System.getenv().findAll { true }
|
||||
|
||||
def call(parameters = [:]) {
|
||||
|
||||
def stepName = 'neoDeploy'
|
||||
@ -203,26 +193,8 @@ def call(parameters = [:]) {
|
||||
|
||||
ToolVerifier.verifyToolVersion(neo, this, configuration)
|
||||
|
||||
JAVA_HOME_CHECK : {
|
||||
|
||||
//
|
||||
// [Q] How is the java executable resolved by neo?
|
||||
// [A] They check for JAVA_HOME. If not present, they
|
||||
// try to resolve it via ```which java```.
|
||||
//
|
||||
def javaHome = envProps.JAVA_HOME
|
||||
def rc = sh script: 'which java', returnStatus: true
|
||||
if(!javaHome && rc == 0) {
|
||||
// java home is not set`, but java is in path.
|
||||
// --> we skip the check and trust that we can work
|
||||
// with java from the path.
|
||||
echo "Skipping tool validate check (java). " +
|
||||
"Java executable in path, but no JAVA_HOME found."
|
||||
} else {
|
||||
def java = new Tool('Java', 'JAVA_HOME', '', '/bin/', 'java', '1.8.0', '-version 2>&1')
|
||||
ToolVerifier.verifyToolVersion(java, this, configuration)
|
||||
}
|
||||
}
|
||||
def java = new Tool('Java', 'JAVA_HOME', '', '/bin/', 'java', '1.8.0', '-version 2>&1')
|
||||
ToolVerifier.verifyToolVersion(java, this, configuration)
|
||||
|
||||
sh """${neoDeployScript} \
|
||||
${commonDeployParams}
|
||||
|
Loading…
x
Reference in New Issue
Block a user