我试图在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;
}
请检查代码并建议正确的方法。
发布于 2017-05-23 20:43:36
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
发布于 2017-05-23 22:59:16
你可以试着这样做。
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");
}
https://stackoverflow.com/questions/44133158
复制相似问题