gpt4 book ai didi

jenkins - Groovy:读取数组中文件的内容并为某些内容进行 grep

转载 作者:行者123 更新时间:2023-12-02 20:46:42 24 4
gpt4 key购买 nike

我正在尝试在 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

关于jenkins - Groovy:读取数组中文件的内容并为某些内容进行 grep,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44133158/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com