请记住,
sh(returnStdout: true, script:...)返回的
String变量
branch_exists_in_angular是字符串而不是数字。在Groovy(包括Jenkins Groovy
CPS环境)中,以下表达式始终求值为
true:
if ('0') { echo "0 is 0"}if ('1') { echo "1 is 1"}sh使用
(expr) as Integer以下命令将step 的结果转换为整数:
branch_exists_in_angular = sh(script: 'git ls-remote --heads $ANGULAR_REPO $EXTRA_BRANCH | wc -l', returnStdout: true) as Integer
它会使你的变量是一个类型的
Integer,然后
if (0)将评估对
false和
if (1)将评估到
true。



