问题
I have a deployment script I'm trying to set. I'm trying to set an environmental variable called DEPLOY_DATE equal to now.
"scripts": {
"deploy": "kubectl set env deploy/api DEPLOY_DATE=\"$(date)\""
}
The problem is this just sets DEPLOY_DATE equal to $(date) instead of the actual date.
Is there anyway package.json script can actually evaluate the date variable, or any variable?
回答1:
I think it's correctly set, try the following to verify:
"deploy": "kubectl set env deploy/api DEPLOY_DATE=\"$(date)\"; echo $DEPLOY_DATE"
If date is printed all is OK. I tested with :
"deploy": "export DEPLOY_DATE=\"$(date)\"; echo $DEPLOY_DATE"
And when run "npm run deploy" I obtain:
> test@1.0.0 deploy /home/me/projects/test
> export DEPLOY_DATE="$(date)"; echo $DEPLOY_DATE
mar abr 10 00:24:00 CEST 2018
来源:https://stackoverflow.com/questions/49741967/passing-date-to-package-json-script