我期待类似branch = "v1"
或大于1的内容,如v2或v3。
我需要能够做一些类似的事情:
if branch == "v2" or greater than 2
do stuff
分支也可以是不满足if条件的master
、feature/something
、v1
等
你可以这样做
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可以使条件运行