我有一个Jenkins管道,它通过SCM触发一个Jenkins groovy脚本,此脚本将创建一个文件(如果文件不存在),并写入其他内容,它将更新文件并做一些事情,此文件需要删除。
下面是创建、写入和更新文件的代码。
node(node_label){
if (fileExists ( file_path+'/'+file_name ) ){
def readContent = readFile file_path+'/'+file_name
writeFile file: file_path+'/'+file_name, text: readContent+'\r\n'+data
}else{
writeFile file: file_path+'/'+file_name, text:data
}
}
在做了一些事情后,我需要删除这个文件,我试着删除这个如下,但它不工作。
def Delfile = new File(path+'/'+file_name)
Delfile.delete()
1条答案
按热度按时间y0u0uwnf1#
我有以下手动工作区清理,所以正如你提到的,它应该工作,以及检查下面。
我假设您可能没有正确获取文件路径
所以,清理工作的核心是: