Jenkins检查环境.以字母(v)开头,后跟数字(v1)的BRANCH大于1



我期待类似branch = "v1"或大于1的内容,如v2或v3。

我需要能够做一些类似的事情:

if branch == "v2" or greater than 2
do stuff

分支也可以是不满足if条件的masterfeature/somethingv1

你可以这样做

String getVersion = env.BRANCH_NAME
def getBranchTag = getVersion.substring(1)
if ( "$getBranchTag" > 1) {
do stuff
}

好的,所以解决方案很简单:

String thisVersion = "v2".replace("v", ""); // e.g v2
String otherVersion = "v1".replace("v", ""); // e.g v1
def versionLaterThan(x) { x.toInteger() > 1}
println("thisVersion: " + versionLaterThan(thisVersion));
println("otherVersion: " + versionLaterThan(otherVersion));

输出:

thisVersion: true
otherVersion: false

如果thisVersion为真,则I可以使条件运行

最新更新