[英]Read a file and compare the contents of the file to pipeline parameters using Groovy
[英]Groovy: Read contents of a file in an array and grep for something
我正在嘗試在GROOVY腳本中實現以下操作,但出現錯誤:讀取數組中HTML文件的內容,然后對該數組中的內容進行grep
讀取。
def file1 = new File("/path/to/the/file/xyz.html");
def lines = file1.readLines()
if ((-e "/path/to/the/file/xyz.html") and (!(grep /jira.bugtracker.com/, lines))
{
println (" the changes are present\n");
exit 0;
}
else
{
println (" the changes are not present\n");
exit 1;
}
請查看代碼並提出正確的方法。
def file1 = new File("/path/to/the/file/xyz.html" )
def lines = file1.readLines()
def found = lines.find{ line-> line =~ /jira.bugtracker.com/ }
println ("the changes are ${ found ? '' : 'not ' }present")
return found ? 0 : 1
您可以嘗試這樣。
if ( new File("/path/to/the/file/xyz.html").text?.contains("jira.bugtracker.com")){
println (" the changes are present\n");
} else {
println (" the changes are not present\n");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.