I'm trying to publish the git commit hash to prometheus and for this I need to get the output of the following command and save to file.
git rev-parse HEAD
I'd like to save to gitReleaseVersion.txt
I found some similar post for android here but I'm not able to translate it to kotlin gradle.
Here's what I have but it's not creating any file.
task<Exec>("getVersionInfo"){
doLast {
exec {
commandLine("git rev-parse HEAD > gitReleaseVersion.txt")
}
}
}
Output: no error, no file
and also tried
task<Exec>("getVersionInfo"){
val logFile = file("src/main/resources/gitReleaseVersion.txt")
exec {
commandLine("git rev-parse HEAD").standardOutput.to(logFile)
}
}
Output:
Cannot run program "git rev-parse HEAD" (in directory "/Users/kaigo/code/core/module/base/function-base"): error=2, No such file or directory
The file does exist and if I print the file path, the link resolves to the file.