我正在尝试使用 jenkins 管道生成报告,并设置一个条件来检查生成的文件是否为空。
如果它为空,则转到另一个条件,如果它不为空,则执行其他步骤。
def status = sh(returnStatus: true, script: "git status > output.txt")
File conflict = new File("output.txt")
println "The file ${conflict.absolutePath} has ${conflict.length()} bytes"
if ( "${conflict.length()}" == "0" ) {
println "\u001B[32m[INFO] conflicts are there"
def output = readFile('conflict_output.txt').trim()
println output
}
Run Code Online (Sandbox Code Playgroud)
这是行不通的。Git status 输出有一些数据,并且不应该是 0 字节。每次我运行它都会进入这个 if 条件。
小智 5
您可以使用此代码代替您的代码:
def output_list = readFile("output.txt")
if (output_list.size() == 0) {
// your code
}
Run Code Online (Sandbox Code Playgroud)
您可以根据分隔符拆分文件。
| 归档时间: |
|
| 查看次数: |
5422 次 |
| 最近记录: |