I have a diff in a build string parameter.
To apply it to the repository I need to write it to a file, which is then accessed as part of a shell/batch script.
On the master (running linux) this works fine
def checkOutWithPatch(url, credentials, destination, revision, diff) {
checkout([$class: 'MercurialSCM', clean:true, credentialsId: credentials, revision: revision, source: url, subdir: destination])
if (diff != "")
{
new File(pwd().toString() + "/patch.diff").write(rep_diff)
sh "cd ${destination}; patch -p1 -f < ${pwd()}/patch.diff"
}
}
Now the first hurdle I encountered trying to get the same functionality to run on a slave, is that I can't create files on a slave in that way, permission is denied (even though it's not denied when I do a repository checkout, to be honest I don't really understand how one can work and not the other).
So I decide to try writing a temp file, now experimenting with this bit of code
File diff_file = File.createTempFile("rep",".diff")
diff_file.write(diff)
print diff_file.absolutePath
String fileContents = new File(diff_file.absolutePath).text
print fileContents
I find that it runs fine, and the output from "print fileContents" is the diff I put in, which suggests to me that the temp file is being created.
Except I can't find it! It's not where the print diff_file.absolutePath says it should be, and so far a search of the slave filesystem hasn't shown it up (there are a lot of files, I should probably clean that up).
I thought perhaps jenkins was cleaning the file up when the job ended, but I've tried putting in an input step afterwards so the job remains active while I look, still no luck.
I need to know where it is so I can read it in the batch script to apply the patch (an alternative might have been to send the diff to a shell script as stdin, but that does not seem to be possible).
Anybody know where it goes?