Passing date to package.json script

杀马特。学长 韩版系。学妹 提交于 2021-01-04 08:45:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!