jenkins-pipeline-cache-plugin
jenkins-pipeline-cache-plugin copied to clipboard
hashFiles silently generating empty hash
I'm not sure whats going on yet, but I had inappropriate cache hits, and tracked it down to hashFiles giving the same signature when file content had changed.
Concretely, I write a number of strings to a file:
String hashStrings(List strings) {
// need a java extension perhaps - the sandbox is blocking the
// obvious .digest('SHA-1') method.
// Manual salt to allow rekeying if needed
input = ["serial-1"] + strings
temp_path = pwd(tmp: true)
hash_path = "${temp_path}/cargo-cache-key-vars"
writeFile(file: hash_path, text: input.join('\n'))
echo "hashing ${input.join('\n')}"
hash = sh(script: "md5sum < ${hash_path}", returnStdout: true).split(' ')[0]
hash_files_hash = hashFiles(hash_path)
echo "${hash} ${hash_files_hash}"
return hash
}
Which echos e973e42cfa03aa8c5a826ecffb41431a
d41d8cd98f00b204e9800998ecf8427e
Now that hashFiles hash is a well known hash - a completely empty hash:
echo -n | md5sum
d41d8cd98f00b204e9800998ecf8427e
This code Seems fine IFF it is choosing the Path override.
So I'm not sure. Perhaps something to do with the k8s plugin :/.