You might want to automate your Now deployments. Here is how you can achieve this by using Git and Travis. Every time you push or merge to the master branch a new build and deployment is initiated in Travis CI.
- You need to get a token. Go to the tokens page of your dashboard, under Account Settings, Tokens. Enter the name of the Token (e.g. Travis CI) and hit enter. A new token will be created which you can copy to your clipboard by clicking Copy.
- Create a .travis.yml file in the root of your project.
- Generate a secure variable for your ZEIT token by running the following command with the token you obtained from your ZEIT account. (You need to install The Travis Client):
travis encrypt -r username/repo NOW_TOKEN=xxxxxxxxxxxxxxxxxxxxxxx --add
- Now open your .travis.yml file and add the following:
script: npm run deploy
after_script: npm run alias
secure: <this is your encrypted NOW token. It was added when you ran travis encrypt>
- Open your package.json file and add the following information, adapted for your own deployment. This is used to run the alias command and point your domain to the correct deployment (you could also put this in a now.json file):
- Also add the following 2 scripts to the
script property in your package.json file. These are used by your Travis config. The first is to deploy and the second is used to alias your latest deploy:
"deploy": "now -e NODE_ENV=production --token $NOW_TOKEN --npm",
"alias": "now alias --token=$NOW_TOKEN"
- Test it out by committing your code to Github. Check out your travis-ci.org build feed.