Groovy web console

subscribe to the feed Subscribe
to this
site

Compare Versions

Published 1 month ago by rz
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
List<Integer> versionToList(String version) {
    version.split("\\.").collect {
        try {
            it.toInteger()
        } catch (NumberFormatException e) {
            -1
        }
    }
}

def isPipelineConfigurable(String currentVersion) {
    List currentV = versionToList(currentVersion)
    List supportedV = [1, 46]
    Integer maxIndices = Math.max(currentV.size(), supportedV.size())
    for (Integer i = 0; i < maxIndices; i++) {
        Integer v1 = (i < currentV.size()) ? currentV[i] : 0
        Integer v2 = (i < supportedV.size()) ? supportedV[i] : 0
        if (v1 == v2) {
            continue
        }
        return (v1 > v2)
    }
    return true
}

v = "1.47.1"
println "version=${v}, configurable=${isPipelineConfigurable(v)}"

v = "1.46.2"
println "version=${v}, configurable=${isPipelineConfigurable(v)}"

v = "1.45"
println "version=${v}, configurable=${isPipelineConfigurable(v)}"

v = "1"
println "version=${v}, configurable=${isPipelineConfigurable(v)}"

v = "2"
println "version=${v}, configurable=${isPipelineConfigurable(v)}"