I'm learning Percy and Cypress right now. I'm still working locally, without a CI. Since I have more than 1 project, I have to manually change the Percy token (using export PERCY_TOKEN=myToken in Terminal) every time I switch between projects. Can I avoid this by specifying the token in a file? If so, which one?
Asked
Active
Viewed 432 times
1 Answers
1
Assuming you're using macOS or Linux, if you have a bashrc or zshrc file, you should be able to export the PERCY_TOKEN
as a variable in that file.
export PERCY_TOKEN=myToken
After saving your .*rc
file, you will need to either restart your terminal, or simply source the updated file.
source ~/path/to/.*rc

agoff
- 5,818
- 1
- 7
- 20
-
Thanks for the answer. I added the export in the .zshrc. That's working. It's just that only 1 project is still possible. If I change the project and thus the token, I have to adapt the .zshrc again. Can't you save it in the project? – Michael S. Jan 25 '22 at 14:09
-
Are you using npm and a `package.json` file in your projects? – agoff Jan 25 '22 at 17:04
-
Yes, I am using those 2. – Michael S. Jan 25 '22 at 17:24
-
1Awesome -- take a look at this for recommendations on using dotenv-cli and cross-var to manage variables from a .env file: https://medium.com/@arrayknight/how-to-use-env-variables-in-package-json-509b9b663867 – agoff Jan 25 '22 at 17:43
-
1Great, using `npm i dotenv-cli`, saving the token to a .env file, and then calling with `npm run percy:cypress` works as intended. The script section in package.json contains now `"percy:cypress": "dotenv -- percy exec -- cypress run"`. – Michael S. Jan 26 '22 at 06:22