我想在Jenkins管道作业中使用Switch语句。
def version = "1.2"
switch(GIT_BRANCH) {
case "develop":
result = "dev"
break
case ["master", "support/${version}"]:
result = "list"
break
case "support/${version}":
result = "sup"
break
default:
result = "def"
break
}
echo "${result}"
GIT_BRANCH
等于:
develop
- 返回值为dev
- 确定master
- 返回值为list
- 确定support/1.2
- 返回的值为sup
- 为什么不list
?答案 0 :(得分:16)
我的猜测是frequency.c:19:2: error: invalid use of undefined type ‘struct _jobject’
char deletethis=(char)bits[0];
^~~~
frequency.c:19:28: error: dereferencing pointer to incomplete type ‘struct _jobject’
char deletethis=(char)bits[0];
的类型是GIT_BRANCH
,而String
是"support/${version}"
。如果您将后者转换为GString
它应该有效:
String
两种字符串类型之间的差异在将它们相互比较时无关紧要,但它可能对其他类型的比较很重要,例如:在您的代码中,您隐含地将def version = "1.2"
switch(GIT_BRANCH) {
case "develop":
result = "dev"
break
case ["master", "support/${version}".toString()]:
result = "list"
break
case "support/${version}":
result = "sup"
break
default:
result = "def"
break
}
echo "${result}"
与GString
的元素进行比较。