Reputation: 3776
What would be the best automatic available value to return (eg. in a HTTP function) that gives an unique indication of the current deployed version or timestamp of my functions (so not version of the node runtime)? Looking for e.g. a number or timestamp that gets incremented automatically when I do a new deploy of my functions.
I thought using this:
function currentFileTimestamp() {
var stats = fs.statSync("./index.js");
var mtime = new Date(stats.mtime);
return mtime
}
But this always seams to return Tue Jan 01 1980 00:00:01 GMT+0000 Does the Firebase Admin API have a "current deployed version" timestamp or something that we could use?
Upvotes: 1
Views: 204
Reputation: 35
I just deployed a test function to Google Cloud Functions using the python 3.10
runtime and can confirm that the environment variable is called K_REVISION
as wheatazogg discusses in his post about nodejs10
import os
def testdeployfunction(data,context) :
for name, value in os.environ.items() :
print("{0}: {1}".format(name,value))
return 'OK'
returns:
Upvotes: 0
Reputation: 4670
There are some alternatives that you can give it a try. On Node.js 10 runtime environment there is an environment variable - more information here - called K_REVISION
, where you can find the value from the version of your Cloud Function.
For Python and older Node.js versions there is also an environment variable called X_GOOGLE_FUNCTION_VERSION
that you can also check for the deployed version.
You can get more details on how to use them, with examples in this similar case here.
Upvotes: 1