how to delete a particular file in Jenkins workspace via Jenkins groovy script
i have a Jenkins pipeline, which triggers a Jenkins groovy script via SCM, this script will create a file(if the file is not present) and write else it will update the file and doing some stuffs, this file need to be deleted.
below is the code of creating, writing and updating the file.
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
}
}
after doing some stuffs, i need to delete this file, i tried deleting this as below, but its not working.
def Delfile = new File(path+'/'+file_name)
Delfile.delete()