与字符串比较在詹金斯管道中不起作用

OK9*_*999 2 groovy jenkins-pipeline

任何想法为什么IF-ELSE下面的作品

def checkPrValidity() {
    wordCountStr = sh returnStdout: true, script: 'git diff --ignore-space-at-eol $target_branch..PRbranch src | wc -l' 
    wordCount = wordCountStr.toInteger() //force conversion to int data type 
    if (wordCount == 0) {
        return false;
    } else {
        println("This is a valid PR, continue the job execution")
        return true;
    }
}
Run Code Online (Sandbox Code Playgroud)

而下面的那个没有

def checkPrValidity() {
    wordCountStr = sh returnStdout: true, script: 'git diff --ignore-space-at-eol $target_branch..PRbranch src | wc -l'
    if (wordCountStr == '0') {
        return false;
    } else {
        println("This is a valid PR, continue the job execution")
        return true;
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么我需要专门将a转换stringInteger,而无法将其作为string数据类型进行比较?

FCh*_*FCh 5

尝试添加.trim()到您的sh。因为在输出中可能会有新行,这妨碍了正确的比较。