Proximo
Proximo

Reputation: 6531

Passing date to package.json script

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?

Upvotes: 3

Views: 3658

Answers (1)

4ndt3s
4ndt3s

Reputation: 3467

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:

> [email protected] deploy /home/me/projects/test
> export DEPLOY_DATE="$(date)"; echo $DEPLOY_DATE

mar abr 10 00:24:00 CEST 2018

Upvotes: 4

Related Questions