mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
add multiple versions verification
This commit is contained in:
parent
3c59ac4454
commit
bc6ce8b3ba
@ -5,7 +5,7 @@ import hudson.AbortException
|
||||
|
||||
class VersionUtils implements Serializable {
|
||||
|
||||
def static verifyVersion(script, name, executable, version, versionOption) {
|
||||
def static verifyVersion(script, name, executable, String version, versionOption) {
|
||||
|
||||
script.echo "Verifying $name version $version or compatible version."
|
||||
|
||||
@ -22,4 +22,26 @@ class VersionUtils implements Serializable {
|
||||
}
|
||||
script.echo "Verification success. $name version ${installedVersion.toString()} is installed."
|
||||
}
|
||||
|
||||
def static verifyVersion(script, name, executable, Map versions, versionOption) {
|
||||
|
||||
def toolVersion
|
||||
try {
|
||||
toolVersion = script.sh returnStdout: true, script: """#!/bin/bash
|
||||
$executable $versionOption"""
|
||||
} catch(AbortException e) {
|
||||
throw new AbortException("The verification of $name failed. Please check '$executable'. $e.message.")
|
||||
}
|
||||
for (def entry : versions) {
|
||||
if (toolVersion.contains(entry.getKey())) {
|
||||
def installedVersion = new Version(toolVersion)
|
||||
def expectedVersion = entry.getValue()
|
||||
script.echo "Verifying $name version $expectedVersion or compatible version."
|
||||
if (!installedVersion.isCompatibleVersion(new Version(expectedVersion))) {
|
||||
throw new AbortException("The installed version of $name is ${installedVersion.toString()}. Please install version $expectedVersion or a compatible version.")
|
||||
}
|
||||
script.echo "Verification success. $name version ${installedVersion.toString()} is installed."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,16 +15,29 @@ class ToolDescriptor implements Serializable {
|
||||
final stepConfigurationKey
|
||||
final executablePath
|
||||
final executableName
|
||||
final version
|
||||
final singleVersion
|
||||
final multipleVersions
|
||||
final versionOption
|
||||
|
||||
ToolDescriptor(name, environmentKey, stepConfigurationKey, executablePath, executableName, version, versionOption) {
|
||||
ToolDescriptor(name, environmentKey, stepConfigurationKey, executablePath, executableName, String singleVersion, versionOption) {
|
||||
this.name = name
|
||||
this.environmentKey = environmentKey
|
||||
this.stepConfigurationKey = stepConfigurationKey
|
||||
this.executablePath = executablePath
|
||||
this.executableName = executableName
|
||||
this.version = version
|
||||
this.singleVersion = singleVersion
|
||||
this.multipleVersions = [:]
|
||||
this.versionOption = versionOption
|
||||
}
|
||||
|
||||
ToolDescriptor(name, environmentKey, stepConfigurationKey, executablePath, executableName, Map multipleVersions, versionOption) {
|
||||
this.name = name
|
||||
this.environmentKey = environmentKey
|
||||
this.stepConfigurationKey = stepConfigurationKey
|
||||
this.executablePath = executablePath
|
||||
this.executableName = executableName
|
||||
this.singleVersion = ''
|
||||
this.multipleVersions = multipleVersions
|
||||
this.versionOption = versionOption
|
||||
}
|
||||
|
||||
@ -95,7 +108,8 @@ class ToolDescriptor implements Serializable {
|
||||
def verifyVersion(script, configuration) {
|
||||
|
||||
def executable = getToolExecutable(script, configuration, false)
|
||||
VersionUtils.verifyVersion(script, name, executable, version, versionOption)
|
||||
if (singleVersion) VersionUtils.verifyVersion(script, name, executable, singleVersion, versionOption)
|
||||
if (multipleVersions) VersionUtils.verifyVersion(script, name, executable, multipleVersions, versionOption)
|
||||
}
|
||||
|
||||
def getMessage() {
|
||||
|
Loading…
Reference in New Issue
Block a user